如何使用python引用字符串中的整数?我对编码完全陌生,我正在尝试做这个bug收集练习,用户将输入一周内每天收集的bug数量,并在周末显示收集到的bug总数。在
这是我目前掌握的密码。在
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提示符来询问用户 “第一天你收集了多少虫子?” “第二天你收集了多少虫子?” 等等。在
我该怎么做?在
我个人很喜欢
format()
。你可以这样写代码:range(1, 8)
经过day = 1
到{你可以试试
我的方法如下。在
要阅读字符串格式:http://www.learnpython.org/en/String_Formatting
我写了一篇关于原始输入和出于安全目的的输入的文章,如果你感兴趣的话:https://medium.com/@GallegoDor/python-exploitation-1-input-ac10d3f4491f
来自Python文档:
编程一开始似乎让人不知所措,坚持下去你不会后悔的。祝你好运,我的朋友!在
相关问题 更多 >
编程相关推荐