PYTHON ASSIGNMENT 3.5.2 Espresso Prices Drink types: Americano Espresso Cappucci
ID: 3581973 • Letter: P
Question
PYTHON ASSIGNMENT 3.5.2
Espresso Prices
Drink types:
Americano
Espresso
Cappuccino
Sizes:
Medium, 12 oz.
Large, 16 oz
Price calculation:
The pricing on Americano is the simplest. Mediums are $0.99 per cup; larges, $1.29 per cup.
The pricing on Espresso is a bit more complicated. $1.75 per cup for medium; $2.25 per cup for large. However, there is a volume discount. The mediums are 3 for $4.25; larges are 3 for $5.50.
The pricing on Cappuccino is similar. $2.29 per cup for medium; $2.59 per cup for large. For cappuccino, the volume discount is 10% off for 4 or more cups.
Ex----> output (user input = bold)
Enter number of drinks: 5R
Error in number of drinks. Please try again.
Enter number of drinks: 5.3
Error in number of drinks. Please try again.
Enter number of drinks: 5
Enter drink size (M L): N
Error in drink size. Please try again.
Enter drink size (M L): K
Error in drink size. Please try again.
Enter drink size (M L): M
Enter kind of drink (A E C): C
The order is 5 medium cappuccinos. Total bill: $10.31
Note: This is 5*$2.29 - 10%, or $11.45 - $1.145. The print-out shall always show cents, that is, have exactly two places after the decimal point. (Just let the system round the way that it wants.)
After completing one order, the system shall ask if there is another order. If the answer is yes, the system prompt again for the new order. The single character 'y' is sufficient. The system shall also keep a running total of the orders filled. After the last order, the total value of the orders for the system shall be displayed.
…
The order is 5 medium cappuccinos. Total bill: $10.31
Is there another order? Y
Enter the number of drinks: _
The blank response, just pressing the return key, shall also be interpreted as 'yes'.
…
The order is 5 medium cappuccinos. Total bill: $10.31
Is there another order?
Enter the number of drinks: _
Any response to this question which is neither 'y' nor empty shall be interpreted as "no" and the system shall end.
…
The order is 5 medium cappuccinos. Total bill: $10.31
Is there another order? B
Total orders for the day: $156.28
The use of functions to get the input and calculate the output should make moving from the minimal version to the standard version much easier. In fact, the change should be limited to main, the driver function that just calls the other "worker" functions.
Explanation / Answer
Python code:
def Americano(b):
rate_M = 0.99
rate_L = 1.29
if(b == "M"):
rate = a * rate_M
else:
rate = a * rate_L
return rate
def Espresso(a,b):
rate_M = 1.75
rate_L = 2.25
if(a == 3):
if(b == "M"):
rate = 4.25
else:
rate = 5.50
return rate
if(b == "M"):
rate = a * rate_M
else:
rate = a * rate_L
return rate
def Cappuccino(a,b):
rate_M = 2.29
rate_L = 2.59
if(b == "M"):
rate = a * rate_M
else:
rate = a * rate_L
if(a >= 4):
rate -= rate * .1
return rate
# main function
flag = 1;
total_bill = 0
while(flag):
try:
a = int(raw_input("Enter Number of Drinks: "))
except ValueError:
print "Error in number of drinks. Please try again."
continue;
flag2 = 1
while(flag2 == 1):
b = (raw_input("Enter drink size (M L):"))
if(b != "M" and b!= "L"):
print "Error in drink size. Please try again."
continue;
else :
flag2 = 0
total_rate = 0
c = (raw_input("Enter kind of drink (A E C)"))
if(c == "A"):
total_rate = Americano(b)
if(c == "E"):
total_rate = Espresso(a,b);
if(c == "C"):
total_rate = Cappuccino(a,b)
print "Total bill : $"+ str(total_rate)
d = (raw_input("Is there another order? (Y/N) : "))
if(d == "Y" or d == "y"):
flag = 1
else:
flag = 0
total_bill += total_rate
print "Total order bill: $"+ str(total_bill)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.