0 python for-loop if-statement
我正在尝试制作一个非常基本的帐户减钱系统我正在使用的代码询问用户是否愿意购买价格为200美元的物品.这个想法是200美元将从命名的变量中扣除,total但由于某种原因,这是行不通的.
我不知道是否可以在if语句中嵌套For循环.感谢您的时间
total = 1500
print('Would you like to buy this item?')
print('It costs 100 bucks')
purchaseConfirm = input()
if purchaseConfirm == 'yes':
for num in range(200):
total = total-1 # Why is this thing not functioning???
print(total)
break
Run Code Online (Sandbox Code Playgroud)
我觉得你根本不需要for循环......
total = 1500
print('Would you like to buy this item?')
print('It costs 200 bucks')
purchaseConfirm = input()
cost = 200
if purchaseConfirm == 'yes':
total = total - cost
print(total)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |