如何使用python引用字符串中的整数?我对编码完全陌生,我试图做这个bug收集练习,用户将输入一周中每天收集的错误数量,并显示一周结束时收集的错误总数。参考字符串内的整数? Python
这是我到目前为止的代码。
totalBugs = 0.0
day = 1
for day in range(7):
bugsToday = input('How many bugs did you get on day', day,'?')
totalBugs = totalBugs + bugsToday
print 'You\'ve collected ', totalBugs, ' bugs.'
,所以我试图让内循环bugsToday提示询问 用户“有多少错误你第1天收?” “您在第2天收集了多少个错误?” 等等。
我该怎么做?
你想“从用户输入读取”。检查:http://stackoverflow.com/questions/3345202/python-getting-user-input – doublesharp
可能的重复[如何将字符串转换为整数在Python?](http://stackoverflow.com/questions/642154/如何将字符串转换为整数在Python中) – Paul
's =“34”''n = int(s)''print n + 1'' 35' – Paul