Python自动售货机程序-

huangapple go评论65阅读模式
英文:

python vending machine program-

问题

这个程序允许用户输入货币并选择一个商品以输出价格。

在程序的末尾,if语句中的部分,例如 if purchase_choice == 1: print("************ The item costs $1.00 ************") 以及之后的语句,在输出中没有打印。有人可以帮助我吗?

以下是代码的翻译部分:

print("*********************************")
print("欢迎来到自动贩卖机Bravo!")
print("*********************************")
print("如果您想要选择商品,请将适当的货币投入机器中。")

# 货币充值
num_5Dollars = 5.00
num_Dollars = 1.00
num_Quarters = 0.25
num_Dimes = 0.10
num_Nickels = 0.05
num_Pennies = 0.01

print()
print("请投入:")
if num_5Dollars == 5.00:
    print("5.00美元钞票")
if num_Dollars == 1.00:
    print("1.00美元钞票")
if num_Quarters == 0.25:
    print("0.25美元的硬币")
if num_Dimes == 0.10:
    print("0.10美元的硬币")
if num_Nickels == 0.05:
    print("0.05美元的硬币")
if num_Pennies == 0.01:
    print("0.01美元的硬币")

user_val = float(input())

if int(user_val) == 0:
    print("输入0以取消")

print("任何时候,如果您想取消操作或返回上一个菜单,请输入0。谢谢!:")
print()
print(int(user_val))
print()
print("************ 机器中的总金额是:", user_val, " ************")

# 商品选择
Skittles = {'类型': '1', '价格': 1.00}
Reeses = {'类型': '2', '价格': 1.19}
M_and_M = {'类型': '3', '价格': 1.50}
Chex_Mix = {'类型': '4', '价格': 0.99}
Honey_Bun = {'类型': '5', '价格': 1.99}
types = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]

global 类型
类型 = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]

print()
print("任何时候,如果您想取消操作或返回上一个菜单,请输入0。谢谢!:")
print()

print("如果您想要购买:")
print()
print("Skittles - 输入 '1',(价格= $1.00)")
print("Reeses - 输入 '2',(价格= $1.19)")
print("M_and_M - 输入 '3',(价格= $1.50)")
print("Chex_Mix - 输入 '4',(价格= $0.99)")
print("Honey_Bun - 输入 '5',(价格= $1.99)")

print()
purchase_choice = input()
print("您的输入是:", purchase_choice)

if user_val == 0:
    print('商品选择已停止')
else:
    if purchase_choice == '1':
        print("************ 商品价格为 $1.00 ************")
    if purchase_choice == '2':
        print("************ 商品价格为 $1.19 ************")
    if purchase_choice == '3':
        print("************ 商品价格为 $1.50 ************")
    if purchase_choice == '4':
        print("************ 商品价格为 $0.99 ************")
    if purchase_choice == '5':
        print("************ 商品价格为 $1.99 ************")
英文:

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 ************")

答案1

得分: 1

你需要将用户输入的字符串转换为整数。

purchase_choice = int(input())

英文:

You need to convert the user input string to an integer.

purchase_choice = int(input())

huangapple
  • 本文由 发表于 2023年2月19日 10:20:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定