python vending machine program-
Question:
The program allows the user to enter money and select an item that outputs the price.
Towards the end, the if statements, if purchase_choice == 1: print("************ The item costs $1.00 ************")
and the following statements after that one, is not printing in the output. Can someone help me?
Here’s the code.
print("*********************************")
print("Welcome to Vending Machine Bravo!")
print("*********************************")
print("If you would like to make a selection, please insert the appropriate currency into the machine.")
Currency deposit
num_5Dollars = 5.00
num_Dollars = 1.00
num_Quarters = .25
num_Dimes = .10
num_Nickels = .05
num_Pennies = .01
print()
print("Please enter:")
if num_5Dollars == 5.00:
print("5.00 for $5 bills")
if num_Dollars == 1.00:
print("1.00 for $1 bills")
if num_Quarters == .25:
print(".25 for Quarters")
if num_Dimes == .10:
print(".10 for dimes")
if num_Nickels == .05:
print(".05 for nickels")
if num_Pennies == .01:
print(".01 for pennies")
user_val = float(input())
if int(user_val) == 0:
print("0 to cancel")
print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
print()
print(int(user_val))
print()
print("************ Total money in machine is: ", user_val , "************")
purchase item selection
Skittles = {'type' '1''Price': 1.00}
Reeses = {'type' '2' 'Price': 1.19}
M_and_M = {'type' '3' 'Price': 1.50}
Chex_Mix = {'type' '4' 'Price': 0.99}
Honey_Bun = {'type' '5' 'Price': 1.99}
types = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
global type
type = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
print()
print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
print()
print("If you would like to purchase:")
print()
print("Skittles - type '1', (Price = $1.00)")
print("Reeses - type '2', (Price = 1.19)")
print("M_and_M - type '3', (Price = $1.50)")
print("Chex_Mix - type '4', (Price = $0.99)")
print("Honey_Bun - type '5', (Price = $1.99)")
print()
purchase_choice = input()
print("Your enter is:", purchase_choice)
if user_val == 0:
print('Item selection stopped')
else:
if purchase_choice == 1:
print("************ The item costs $1.00 ************")
if purchase_choice == 2:
print("************ The item costs $1.19 ************")
if purchase_choice == 3:
print("************ The item costs $1.50 ************") [tag:tag-name]
if purchase_choice == 4:
print("************ The item costs $0.99 ************")
if purchase_choice == 5:
print("************ The item costs $1.99 ************")
Answers:
You need to convert the user input string to an integer.
purchase_choice = int(input())
The program allows the user to enter money and select an item that outputs the price.
Towards the end, the if statements, if purchase_choice == 1: print("************ The item costs $1.00 ************")
and the following statements after that one, is not printing in the output. Can someone help me?
Here’s the code.
print("*********************************")
print("Welcome to Vending Machine Bravo!")
print("*********************************")
print("If you would like to make a selection, please insert the appropriate currency into the machine.")
Currency deposit
num_5Dollars = 5.00
num_Dollars = 1.00
num_Quarters = .25
num_Dimes = .10
num_Nickels = .05
num_Pennies = .01
print()
print("Please enter:")
if num_5Dollars == 5.00:
print("5.00 for $5 bills")
if num_Dollars == 1.00:
print("1.00 for $1 bills")
if num_Quarters == .25:
print(".25 for Quarters")
if num_Dimes == .10:
print(".10 for dimes")
if num_Nickels == .05:
print(".05 for nickels")
if num_Pennies == .01:
print(".01 for pennies")
user_val = float(input())
if int(user_val) == 0:
print("0 to cancel")
print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
print()
print(int(user_val))
print()
print("************ Total money in machine is: ", user_val , "************")
purchase item selection
Skittles = {'type' '1''Price': 1.00}
Reeses = {'type' '2' 'Price': 1.19}
M_and_M = {'type' '3' 'Price': 1.50}
Chex_Mix = {'type' '4' 'Price': 0.99}
Honey_Bun = {'type' '5' 'Price': 1.99}
types = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
global type
type = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
print()
print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
print()
print("If you would like to purchase:")
print()
print("Skittles - type '1', (Price = $1.00)")
print("Reeses - type '2', (Price = 1.19)")
print("M_and_M - type '3', (Price = $1.50)")
print("Chex_Mix - type '4', (Price = $0.99)")
print("Honey_Bun - type '5', (Price = $1.99)")
print()
purchase_choice = input()
print("Your enter is:", purchase_choice)
if user_val == 0:
print('Item selection stopped')
else:
if purchase_choice == 1:
print("************ The item costs $1.00 ************")
if purchase_choice == 2:
print("************ The item costs $1.19 ************")
if purchase_choice == 3:
print("************ The item costs $1.50 ************") [tag:tag-name]
if purchase_choice == 4:
print("************ The item costs $0.99 ************")
if purchase_choice == 5:
print("************ The item costs $1.99 ************")
You need to convert the user input string to an integer.
purchase_choice = int(input())