<p>我试图创建一个程序,要求用户输入上次看到哈雷彗星的年份,然后再加上75年和76年,然后输出结果。你知道吗</p>
<pre><code>lastsight = int(input("When was the last sighting? "))
firstsight = lastsight + 75
secondsight = lastsight + 76
print("The next sighting will be in", firstsight, "or", secondsight + ".")
</code></pre>
<p>但是,无论何时运行它,都会出现以下错误:</p>
<pre><code>Traceback (most recent call last):
File "program.py", line 5, in <module>
print("The next sighting will be in", firstsight, "or", secondsight + ".")
TypeError: unsupported operand type(s) for +: 'int' and 'str'
</code></pre>
<p>如果能帮我修一下,我将不胜感激。你知道吗</p>
<p>使用以下选项:</p>
<pre><code>print("The next sighting will be in", firstsight, "or", str(secondsight) + ".")
</code></pre>
<p>正如您正确观察到的,python不会隐式地执行这些转换。你知道吗</p>