Vending Machine Python 3 Exercise - Program ending after last if else statement. I cannot get the program to read "insufficient funds" at the end if the price paid was less than the cost. If the funds are sufficient I cannot get it to print "thank you".
price_multiplier=1.25
option=int(input("Welcome to the vending machine! What would you like to drink today?\n1 - Dr.
Pepper\n2 - Code Red Mountain Dew\n3 - Cherry Coke\t\n4 - Mountain Dew\n(Small - $1.25; Medium
$2.50; Large $3.75)\nPlease Make your selection: "))
if (option==1):
print("You have ordered a Dr. Pepper.")
elif (option==2):
print("You have ordred a Code Red Mountain Dew.")
elif (option==3):
print("You have ordered a Cherry Coke.")
elif (option==4):
print("You have ordered a Mountain Dew.")
else:
print("Invalid selection. Please choose from the menu above.")
option=input("Please select 'S' for small, 'M' for medium, or 'L' for large: ")
if (option=='S'):
price=price_multiplier
print("You have ordered a small. Your total is: $", price)
elif (option=='M'):
price=price_multiplier*2
print("You have ordered a medium. Your total is: $", price)
elif (option=='L'):
price=price_multiplier*3
print("You have ordered a large. Your total is: $", price)
else:
print("Error: Invalid selection.")
print("Please insert amount.")
paid=float(input("Amount inserted: $"))
if paid<price:
print("Insufficient funds, no sale!")
else:
print("Your change is: $", paid-price)
print("Thank you - enjoy your drink!")
Aucun commentaire:
Enregistrer un commentaire