回溯(最近一次调用最后一次)Python 错误

时间:2021-02-19 21:05:45

标签: python

错误

Traceback (most recent call last):
  File "C:\Users\Alex\Python\Lesson01.py", line 5, in <module>
    print("In 10 years you will be ", a+b, "years old")
TypeError: can only concatenate str (not "int") to str

目前我正在学习 Python 3 并遇到此错误。这是什么意思?我也试过 + 而不是逗号,这也不起作用:/

代码如下:

user_input = input("How old are you?\n-> ")

a = user_input
b = 10
print("In 10 years you will be ", a+b, "years old")

1 个答案:

答案 0 :(得分:0)

你必须打印这个:

user_input = int(input("How old are you?\n-> "))

a = user_input
b = 10
print("In 10 years you will be " + str(a+b) + " years old")

这应该可以正常工作