【发布时间】:2013-06-13 18:38:01
【问题描述】:
我正在使用 python 计算如果每 7 秒有一个孩子出生,那么 5 年内将出生多少个孩子。问题出在我的最后一行。当我在它的任一侧打印文本时,如何让变量工作?
这是我的代码:
currentPop = 312032486
oneYear = 365
hours = 24
minutes = 60
seconds = 60
# seconds in a single day
secondsInDay = hours * minutes * seconds
# seconds in a year
secondsInYear = secondsInDay * oneYear
fiveYears = secondsInYear * 5
#Seconds in 5 years
print fiveYears
# fiveYears in seconds, divided by 7 seconds
births = fiveYears // 7
print "If there was a birth every 7 seconds, there would be: " births "births"
【问题讨论】:
-
2020 年要小心(常识,我知道 :D)。打印在 Python3 中已经成为一个函数,现在需要用括号来使用:
print(something)(另外 Python2 从今年开始就已经过时了。)
标签: python string variables printing