2.9. Figuring out an Invoice¶
We can use variables to solve problems like those we might solve in a spreadsheet. Imagine that you had a spreadsheet with an invoice for an office supply company.

A spreadsheet with order information¶
Here’s a program to compute the total price for the invoice:
We don’t really have to create new variables quantity2
and unitPrice2
. We only use those to compute the total for the line, and then we could reuse those variable names.
Activity: CodeLens 2.9.3 (cspnamenumbers_invoice3)
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
Let’s say that apples are $0.40 apiece, and pears are $0.65 apiece. Modify the program below to calculate the total cost (it should print 3.55).
You are welcome to try out the following answers by copying and pasting them into the program above before answering this question: