我的任务是循环一个函数,该函数允许想象中的人花费最多 100 英镑或任何货币,直到 100 用完,在这种情况下脚本就结束了。当脚本运行时,它会将每个值相加并跟踪直到达到阈值!#This line should initialise a variablewhile #I need Finish this line with a loop condition. x = int( input("How much is the next item? ") ) tot = tot+xprint("You cannot afford that! You only have £" + str(100-(tot-x)) + "
2 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
tot = 0
while True:
x = int( input("How much is the next item? ") )
if (tot+x)>100:
print("You cannot afford that! You only have £ {}".format(str(100-(tot))))
continue #you want to skip this iteration and repeat
if tot==100:
print("You cannot afford more!")
break #you want to stop
tot += x
添加回答
举报
0/150
提交
取消