我知道每个人都讨厌问任何与 goto 相关的问题的人,但这是我的问题:我是编码的绝对初学者,所以我正在制作我 11 岁的兄弟提出的一些小练习程序。这是一个程序,您可以在其中选择一个项目,它会从一个帐户中取款。
#!/usr/bin/env python
Acc = 30
print("$1 products: Pepsi, Water, Coke, Sprite")
print("$2 products: Chips, Cookies, Skittles, Twix")
print("$3 products: Amp, Monster, Red Bull, Rockstar")
L1 = ('Pepsi', 'Water', 'Coke', 'Sprite')
L2 = ('Chips', 'Cookies', 'Skittles', 'Twix')
L3 = ('Amp', 'Monster', 'Red Bull', 'Rockstar')
sel = raw_input("Please enter a product: ")
if sel in L1:
print("$1 has been removed from your account.")
Acc = Acc-1
print("You now have $") (Acc), ("left in your account")
if sel in L2:
print("$2 has been removed from your account.")
Acc = Acc-2
print("You now have $") (Acc), ("left in your account")
if sel in L3:
print("$3 has been removed from your account.")
Acc = Acc-3
print("You now have $"), (Acc), ("left in your account")
我希望能够从 If 语句的末尾跳转到用户输入部分之前的点。有没有办法在 Python 中做到这一点?提前致谢。(: