Skip to content
Advertisement

Traceback (most recent call last) Python Error

Error

Traceback (most recent call last):
  File "C:UsersAlexPythonLesson01.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

At the moment I am Learning Python 3 and got this error. What does it mean? I also tried + instead of the comma this is also not working :/

Here is the code:

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

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

Advertisement

Answer

You have to print this:

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")

this should work fine

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement