Python自动售货机程序-

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

python vending machine program-

问题

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

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

以下是代码的翻译部分:

  1. print("*********************************")
  2. print("欢迎来到自动贩卖机Bravo!")
  3. print("*********************************")
  4. print("如果您想要选择商品,请将适当的货币投入机器中。")
  5. # 货币充值
  6. num_5Dollars = 5.00
  7. num_Dollars = 1.00
  8. num_Quarters = 0.25
  9. num_Dimes = 0.10
  10. num_Nickels = 0.05
  11. num_Pennies = 0.01
  12. print()
  13. print("请投入:")
  14. if num_5Dollars == 5.00:
  15. print("5.00美元钞票")
  16. if num_Dollars == 1.00:
  17. print("1.00美元钞票")
  18. if num_Quarters == 0.25:
  19. print("0.25美元的硬币")
  20. if num_Dimes == 0.10:
  21. print("0.10美元的硬币")
  22. if num_Nickels == 0.05:
  23. print("0.05美元的硬币")
  24. if num_Pennies == 0.01:
  25. print("0.01美元的硬币")
  26. user_val = float(input())
  27. if int(user_val) == 0:
  28. print("输入0以取消")
  29. print("任何时候,如果您想取消操作或返回上一个菜单,请输入0。谢谢!:")
  30. print()
  31. print(int(user_val))
  32. print()
  33. print("************ 机器中的总金额是:", user_val, " ************")
  34. # 商品选择
  35. Skittles = {'类型': '1', '价格': 1.00}
  36. Reeses = {'类型': '2', '价格': 1.19}
  37. M_and_M = {'类型': '3', '价格': 1.50}
  38. Chex_Mix = {'类型': '4', '价格': 0.99}
  39. Honey_Bun = {'类型': '5', '价格': 1.99}
  40. types = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
  41. global 类型
  42. 类型 = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
  43. print()
  44. print("任何时候,如果您想取消操作或返回上一个菜单,请输入0。谢谢!:")
  45. print()
  46. print("如果您想要购买:")
  47. print()
  48. print("Skittles - 输入 '1',(价格= $1.00)")
  49. print("Reeses - 输入 '2',(价格= $1.19)")
  50. print("M_and_M - 输入 '3',(价格= $1.50)")
  51. print("Chex_Mix - 输入 '4',(价格= $0.99)")
  52. print("Honey_Bun - 输入 '5',(价格= $1.99)")
  53. print()
  54. purchase_choice = input()
  55. print("您的输入是:", purchase_choice)
  56. if user_val == 0:
  57. print('商品选择已停止')
  58. else:
  59. if purchase_choice == '1':
  60. print("************ 商品价格为 $1.00 ************")
  61. if purchase_choice == '2':
  62. print("************ 商品价格为 $1.19 ************")
  63. if purchase_choice == '3':
  64. print("************ 商品价格为 $1.50 ************")
  65. if purchase_choice == '4':
  66. print("************ 商品价格为 $0.99 ************")
  67. if purchase_choice == '5':
  68. 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.

  1. print("*********************************")
  2. print("Welcome to Vending Machine Bravo!")
  3. print("*********************************")
  4. print("If you would like to make a selection, please insert the appropriate currency into the machine.")
  5. Currency deposit
  6. num_5Dollars = 5.00
  7. num_Dollars = 1.00
  8. num_Quarters = .25
  9. num_Dimes = .10
  10. num_Nickels = .05
  11. num_Pennies = .01
  12. print()
  13. print("Please enter:")
  14. if num_5Dollars == 5.00:
  15. print("5.00 for $5 bills")
  16. if num_Dollars == 1.00:
  17. print("1.00 for $1 bills")
  18. if num_Quarters == .25:
  19. print(".25 for Quarters")
  20. if num_Dimes == .10:
  21. print(".10 for dimes")
  22. if num_Nickels == .05:
  23. print(".05 for nickels")
  24. if num_Pennies == .01:
  25. print(".01 for pennies")
  26. user_val = float(input())
  27. if int(user_val) == 0:
  28. print("0 to cancel")
  29. print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
  30. print()
  31. print(int(user_val))
  32. print()
  33. print("************ Total money in machine is: ", user_val , "************")
  34. purchase item selection
  35. Skittles = {'type' '1''Price': 1.00}
  36. Reeses = {'type' '2' 'Price': 1.19}
  37. M_and_M = {'type' '3' 'Price': 1.50}
  38. Chex_Mix = {'type' '4' 'Price': 0.99}
  39. Honey_Bun = {'type' '5' 'Price': 1.99}
  40. types = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
  41. global type
  42. type = [Skittles, Reeses, M_and_M, Chex_Mix, Honey_Bun]
  43. print()
  44. print("At any point if you wish to cancel operation or go back to last menu, please enter 0. Thank you!:")
  45. print()
  46. print("If you would like to purchase:")
  47. print()
  48. print("Skittles - type '1', (Price = $1.00)")
  49. print("Reeses - type '2', (Price = 1.19)")
  50. print("M_and_M - type '3', (Price = $1.50)")
  51. print("Chex_Mix - type '4', (Price = $0.99)")
  52. print("Honey_Bun - type '5', (Price = $1.99)")
  53. print()
  54. purchase_choice = input()
  55. print("Your enter is:", purchase_choice)
  56. if user_val == 0:
  57. print('Item selection stopped')
  58. else:
  59. if purchase_choice == 1:
  60. print("************ The item costs $1.00 ************")
  61. if purchase_choice == 2:
  62. print("************ The item costs $1.19 ************")
  63. if purchase_choice == 3:
  64. print("************ The item costs $1.50 ************") [tag:tag-name]
  65. if purchase_choice == 4:
  66. print("************ The item costs $0.99 ************")
  67. if purchase_choice == 5:
  68. 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:

确定