Activity: Cash Register

In this chapter, you learned about data types and variables that hold string, integer and floating-point values. You also learned how to glue strings together with concatenation and perform simple numeric addition, subtraction, multiplication and division. For this project, you are going to put all those skills to use with a simple Cash Register program.

Reminder - Your Coding Platform
In the first chapter activity, you learned how to use our online Python engine to submit projects for grading. Or, you may have followed other instructions to code and test Python programs on your own computer and submit them to your teacher separately. Please review the first chapter activity instructions and your choice of a coding platform, if needed, for details on how to complete and submit this project. Your project might be auto-graded by our system, or it may be graded by your teacher.

Background - Calculating A Bill of Sale
When you go to the store and purchase some items, the total amount of your purchase is calculated at the cash register when you check out. Do you know exactly how your total payment is calculated? There are three basic pieces of information that you need to know:

How many items are you purchasing?
What is the cost of each item?
What is the tax rate?
Let's assume that you only buy one kind of item, like a shirt, and the cost for each shirt is the same. As you might guess, these pieces of information can be stored in Python variables. An integer variable will nicely hold the number of items you want to buy, and a floating-point variable will store the price per item.

numItems = 3
costPerItem = 12.50
Copy
Now, your sub-total is the price you are going to pay before taxes are added. The sub-total is calculated by multiplying together the number of items and the cost per item.

subTotal = numItems * costPerItem
Copy
Great, now the last step is to calculate and add tax to the sub-total. A tax rate is expressed as a percentage like 6% or a decimal like 0.06.

taxRate = 0.06
Copy
The tax rate is multiplied by the sub-total and that extra tax amount is then added to the sub-total to find your total sales price.

taxAmount = subTotal * taxRate
totalPrice = subTotal + taxAmount
Copy
Now that you understand the math behind a sale, it's time to demonstrate your skills with a cash register program!

Activity Requirements
In this activity, you are going to create a Python program that will calculate and print a sales receipt from a cash register. Your receipt will show the number of items purchased, the cost per item, the sub-total, the tax rate, the tax amount and the total sales price.

In all activities throughout the course, to receive maximum credit from our auto-grader, be sure to match the required variable names and program output exactly. Spelling errors, incorrect variable names, case-sensitivity issues and inexact program may cause your program to fail a test case!
Create your Python program by completing the following steps:

Start your Python code with a comment at the top showing your name
Declare and initialize Python variables as follows:
numItems should hold the value 4
costPerItem should hold the value 10.00
taxRate should hold the value 0.08
Next, add a statement to calculate and store the sub-total in a variable named subTotal
Next, add a statement to calculate the amount of tax and store the result in a variable called taxAmount
Then, add a statement to calculate the total price and store the amount in a variable called totalPrice
Great, you are now done with the math and need to show the full receipt to the screen. We want the receipt to be formatted exactly as follows:

SALES RECEIPT
Number of items : 4
Cost per item : $10.0
Tax rate : 0.08
Tax amount : $3.2
TOTAL SALE PRICE: $43.2
Remember that you can concatenate (join) together strings and numbers by using the plus sign (+) and the str() function to convert a number to a string. So, for example, you could print() the second output line with this statement:

print("Number of items : " + str(numItems))
Copy
Add 6 print() statements to display the 6 lines in this receipt. You want to match the output lines exactly as demonstrated above.
Use your variables in the print() statements as demonstrated above. Do not hard-code expected numbers in the output.
Remember to use the str() function when needed to convert numbers to strings.
Remember to add the currency symbol (like $) to the front of numbers that are dollar amounts.
Use enough spacing to line up the colons as shown in the example.
Activity Results
When you are done, run your code and verify that your cash receipt is printed to the screen. Are all the calculated amounts correct? Then, temporarily change each of the first three numeric variables (numItems, costPerItem and taxRate) and re-run your program. You should see each output line changes to reflect the new data and calculated amounts.

Here are two more example outputs that use some different initial values in the first three numeric variables.

SALES RECEIPT
Number of items : 5
Cost per item : $5.5
Tax rate : 0.06
Tax amount : $1.65
TOTAL SALE PRICE: $29.15
SALES RECEIPT
Number of items : 100
Cost per item : $3.75
Tax rate : 0.09
Tax amount : $33.75
TOTAL SALE PRICE: $408.75
When you have verified your logic, be sure to change the numItems, costPerItem and taxRate values back to 4, 10.00 and 0.08 as specified in Step 2 before you submit your work.
Activity Rubric
If your project is being automatically graded by our system, your grade will be calculated from 0 to 100 as follows:

Points Description
10 Add comment with name as first line of code
10 Declare and use numItems variable
10 Declare and use costPerItem variable
10 Declare and use taxRate variable
10 Declare and use subTotal variable
10 Declare and use taxAmount variable
10 Declare and use totalPrice variable
10 Use addition where needed to calculate results
10 Use multiplication where needed to calculate results
10 Program produces the correct output
Remember to use the exact variable names described in the activity instructions, use the correct number of items (4), cost per item (10.00) and tax rate (0.08) and format your output exactly as shown above. Case-sensitivity, correct variable names, numeric values, and spacing are all important!

In this activity, students will learn how to calculate a total sales price based on the number of items, the price per item, and the local tax rate. Students will use their Python skills to store these input values in variables, then perform the necessary math to calculate the sub-total, tax amount and total price. Finally, the program should print out a complete receipt to the screen as specified in the activity instructions.

# Code by [Your Name]

# Declare and initialize variables
numItems = 4
costPerItem = 10.00
taxRate = 0.08

# Calculate sub-total
subTotal = numItems * costPerItem

# Calculate tax amount
taxAmount = subTotal * taxRate

# Calculate total price
totalPrice = subTotal + taxAmount

# Print out receipt
print("SALES RECEIPT")
print("Number of items : " + str(numItems))
print("Cost per item : $" + str(costPerItem))
print("Tax rate : " + str(taxRate))
print("Tax amount : $" + str(taxAmount))
print("TOTAL SALE PRICE: $" + str(totalPrice))