这个问题已经回答了,如果有人想看代码,请看下面的评论。真的很抱歉。感谢那些已经回复的人
发布于 2018-09-26 02:46:49
Python关心缩进,所以一定要注意这一点。我假设你一旦命中>100就想退出,所以我在这里添加了一条break语句。
下面是你的代码应该是什么样子的:
pocketMoney=0.01
totalMoney=0
week=0
for week in range(1,27):
print("It is week", week)
print("You will get £",pocketMoney)
pocketMoney=pocketMoney*2
totalMoney=pocketMoney-0.01
if pocketMoney>=100:
print("It will be", week," to get £100")
break;
print("Your total amount of money is £",totalMoney)编辑:我已经删除了week=week+1部分,因为这是一个for循环,所以不需要它。
发布于 2018-09-26 02:54:31
下面是我的代码:
pocketMoney = 0.01
totalMoney = 0
for week in range(1,27):
print("It is week "+str(week)+".")
print("You will get £"+str(pocketMoney)+".")
pocketMoney= pocketMoney*2
totalMoney = pocketMoney-0.01
if pocketMoney>=100:
print("It will be "+str(week)+" weeks to get £100.")
break
print("Your total amount of money is £"+str(totalMoney)+".")我去掉了week=0和week=week+1,因为不需要它们。我还对打印的内容进行了一些格式化。
https://stackoverflow.com/questions/52504708
复制相似问题