首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python week counting-现在更改

Python week counting-现在更改
EN

Stack Overflow用户
提问于 2018-09-26 02:34:00
回答 2查看 221关注 0票数 0

这个问题已经回答了,如果有人想看代码,请看下面的评论。真的很抱歉。感谢那些已经回复的人

EN

回答 2

Stack Overflow用户

发布于 2018-09-26 02:46:49

Python关心缩进,所以一定要注意这一点。我假设你一旦命中>100就想退出,所以我在这里添加了一条break语句。

下面是你的代码应该是什么样子的:

代码语言:javascript
复制
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循环,所以不需要它。

票数 2
EN

Stack Overflow用户

发布于 2018-09-26 02:54:31

下面是我的代码:

代码语言:javascript
复制
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=0week=week+1,因为不需要它们。我还对打印的内容进行了一些格式化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52504708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档