In: Computer Science
Python Programming- 9.10 MT Practice Simple Food Receipt 2B
"""
Enhance your simple food receipt
a. Ask the user for inputs about two food items using the following
prompts in turn [add a space after each
question mark]. Do not forget to assign each user
entry to a unique variable name (do not display the Note to add a
space just use print() to add a space between each
set of input statements):
Item 1? [add a space after the question mark]
Item 1 price? [add a space after the question mark]
Item 1 number? [add a space after the question mark]
[Note: add space here using print()]
Item 2? [add a space after the question mark]
Item 2 price? [add a space after the question mark]
Item 2 number? [add a space after the question mark]
[Note: add space here using print()]
Item 3? [add a space after the question mark]
Item 3 price? [add a space after the question mark]
Item 3 number? [add a space after the question mark]
[Note: add space here using print()]
b. Convert the price and quantity variables to integers
c. Calculate the total cost for the order by calculating each
item's total price by
multiplying price and quantity for each item and then adding up the
total prices for the three items
d. Calculate the total cost plus tax for the order by multiplying
the total cose calculated in c by the tax
rate of .0545 (5.45 percent tax) then adding the tax to the total
cost
e. Display the results using the structure below. Edit the format
string "${:,.2f}".format(identfier) to format the
results of your calculation as currency with the PHP currency type,
a space between PHP and the calculated costs,
and 1 decimal place:
RECEIPT
You ordered: [Item 1] [Item 2] [Item 3]
Your cost: [total price for all items calculated in 3c above,
formatted with PHP currency and 1 decimal place]
Your cost w tax: {total cost plus tax calculated in 3d above,
formatted with PHP currency and 1 decimal place}
"""
#Start your code below
PYTHON CODE:
# getting item 1 name
item1_name = input('Item 1? ')
# getting item 1 price
item1_price = input('Item 1 price? ')
# getting item 1 quantity
item1_quantity = input('Item 1 number? ')
print()
# getting item 2 name
item2_name = input('Item 2? ')
# getting item 2 price
item2_price = input('Item 2 price? ')
# getting item 2 quantity
item2_quantity = input('Item 2 number? ')
print()
# getting item 3 name
item3_name = input('Item 3? ')
# getting item 3 price
item3_price = input('Item 3 price? ')
# getting item 3 quantity
item3_quantity = input('Item 3 number? ')
print()
# converting the string to float, integer
item1_price = float(item1_price)
item1_quantity = int(item1_quantity)
item2_price = float(item2_price)
item2_quantity = int(item2_quantity)
item3_price = float(item3_price)
item3_quantity = int(item3_quantity)
# calculating the total cost
total_cost = item1_price * item1_quantity + (item2_price * item2_quantity) + (item3_price * item3_quantity)
# calculating tax and adding with total cost
total_cost_with_tax = total_cost + total_cost * .0545
# displaying the result
print('You ordered: {0:s} {1:s}
{2:s}'.format(item1_name,item2_name,item3_name))
print('Your cost: ${:,.1f}'.format(total_cost))
print('Your cost w tax: ${:,.1f}'.format(total_cost_with_tax))
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT: