2.13 Ch 2 Program: Food receipt (Python 3) Note: When accuracy is essential, flo
ID: 3742021 • Letter: 2
Question
2.13 Ch 2 Program: Food receipt (Python 3)
Note: When accuracy is essential, floats are not used to represent currency due to rounding and accumulation errors. Python provides several primitives specifically developed to implement financial applications. However, these topics are beyond the scope of this lab.
(1) Prompt the user to input a food item name, price, and quantity. Output an itemized receipt. (Submit for 2 points)
Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.
(2) Extend the program to prompt the user for a second item. Output an itemized receipt. (Submit for 2 points, so 4 points total)
(3) Extend again to output a third receipt that adds a mandatory 15% gratuity to the total cost. Output the total cost, the cost of gratuity, and the grand total. (Submit for 3 points, so 7 points total)
Explanation / Answer
Answer :
1) Prompt the user to input a food item name, price, and quantity. Output an itemized receipt.
2) Extend the program to prompt the user for a second item. Output an itemized receipt.
3) Extend again to output a third receipt that adds a mandatory 15% gratuity to the total cost.
itemName = input('Enter food item name: ')
price = float(input('Enter item price: '))
quantity = int(input('Enter item quantity: '))
hotdog = (quantity * price)
print(' RECEIPT')
print(quantity, itemName, '@ $', price, '= $', hotdog)
print('Total cost: $', hotdog)
print(' ')
item = input('Enter second food item name: ')
prices = float(input('Enter item price: '))
quantitys = int(input('Enter item quantity: '))
icecream = (quantitys * prices)
print(' RECEIPT')
print(quantity, itemName, '@ $', price, '= $', hotdog)
print(quantitys, item, '@ $', prices, '= $', icecream)
print('Total cost: $', icecream + hotdog)
gratuity = (hotdog + icecream) * .15
print(' 15% gratuity: $', gratuity)
print('Total with tip: $', hotdog + icecream + gratuity)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.