Python error explained
TypeError: what it means and how to fix it
You tried to join text and a number with +.
The message
TypeError: can only concatenate str (not "int") to str
What it means
+ joins two strings or adds two numbers, but Python will not guess what you mean when one side is text and the other is a number. You have to convert one of them first.
Common causes
- Building a message with + and a number
- Adding to a value that came from input(), which is always text
- Reading numbers from a file without converting them
Example that raises it
age = 30
print("Next year you will be " + age + 1)
The fix
age = 30
print(f"Next year you will be {age + 1}")
Tip: f-strings convert numbers for you, so f"{age}" is the easiest fix. Use int() or float() when you need to do maths on text from input().
Fix the broken version yourself in the editor on this page. It runs real Python in your browser.