【发布时间】:2016-10-03 09:21:40
【问题描述】:
我需要编写一个程序,从 for 循环中获取最后一个数字(如果它超过某个数字)并将其放在 while 循环中。我在下面留下了未完成的代码。
t=0
num=int(input("How many presents do you want to buy?: "))
for i in range(num):
t=t+int(input("Please enter the price of a present")
while t>'200':
print("Limit Exceeded.")
print("You need to get rid of the " #price from the previous loop
【问题讨论】:
-
您有很多不匹配的括号,并且您无法将 int 与字符串进行比较:
t>200将优于t>'200'。我真的无法进一步帮助您,因为我不确定您要使用此代码实现什么目标。
标签: python for-loop while-loop