Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python for Beginners Correct errors

what is wrong with this TypeError: a=5 print(5 + a)

I'm doing an exercise but I'm not understanding what the TypeError is in it because I've tried different ways too

errors.py
print("Hello")

name = "shannon"
print("name")

print("Let's do some math!")
a = "5"
print(5 + a)

print("Thanks for playing along!")

1 Answer

andren
andren
28,558 Points

Type error in this case means that you are trying to do something with two different types that is not supported.

5 is an int (number) while a is a string (text) variable. You cannot add an int and a string together using the + operator in Python. Even if the string contains a number.

Anything wrapped in quotes will be treated as a string regardless of what it is. To have something treated as an actual number you need to type it without quotes, like this:

a = 5
print(5 + a)

Then that error will go away.