Python Test (Easy)
user_8473128851
python
4 years ago
2.3 kB
9
Indexable
def isNumber(a):
try:
int(a)
return True
except ValueError:
return False
def pickMenu():
menuID = str(input())
if menuID == "0":
return "End program"
elif menuID == "1":
return 15
elif menuID == "2":
return 16.5
elif menuID == "3":
return 10
elif menuID == "4":
return 12.5
elif menuID == "5":
return 10
elif menuID == "6":
return 8
elif menuID == "7":
return 11.5
elif menuID == "8":
return 12
else:
return "[That's not an option]"
def pickQuantity(price):
print("Quantity for the item:")
print("((Type in 0 to cancel ordering this item))")
quantity = str(input())
if isNumber(quantity):
if quantity == "0":
return "Cancel"
elif int(quantity) > 0:
return quantity
else:
return "[That's not an option]"
else:
return "[That's not an option]"
total = 0;
ordering = True;
#Main code begins
print("--- Welcome to our restaurant! ---")
while ordering:
print("============================================")
print("(1) Food 1 15k || (5) Drink 1 10k")
print("(2) Food 2 16.5k || (6) Drink 2 8k")
print("(3) Food 3 10k || (7) Drink 3 11.5k")
print("(4) Food 4 12.5k || (8) Drink 4 12k")
print("============================================\n")
print("Please choose an item by inputing the number:")
if total > 0:
print("((Type in 0 to finish this order))")
else:
print("((Type in 0 to cancel this order))")
chosenMenu = pickMenu()
if isNumber(chosenMenu):
while True:
chosenQuantity = pickQuantity(chosenMenu)
if isNumber(chosenQuantity):
total += (float(chosenMenu) * float(chosenQuantity))
break
elif chosenQuantity == "Cancel":
break
else:
print(chosenQuantity)
print("\n")
elif chosenMenu == "End program":
ordering = False
else:
print(chosenMenu)
if total > 0:
print("\nTOTAL: " + str(total) + "K")
print("\nThank you! See you next time!")Editor is loading...