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 trialEmmanuel Nyirenda
478 PointsTypeError: unsupported operand type(s) for +: 'int' and 'str' (5 + "a")?
how do i fix the mistake?
print("Hello")
print("name")
print("hello")
print("Let's do some math!")
print(5 + "a")
print("5 + 5")
print("Thanks for playing along!")
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! This line:
print(5 + "a")
contains both an integer and a string. Python cannot add them together. You can either change them both to numbers or change them both to strings. Your choice!
either:
print(5 + 2)
or:
print("5" + "a")
In the first example we are printing the result of adding two integers. In the second example we are printing the result of concatenating two strings.
Hope this helps!
Blake Handson
1,642 PointsYou are attempting to add together two different data types - python gets grumpy when we try to do this. So to get around this you can concatenate them, to do this you will need to convert them both to strings.
print("5" + "a")
Hope that helps you.
Blake