I am new to Python, will someone be able to figure out what this means
HarryPall (1)

Traceback (most recent call last):
File "python", line 4, in <module>
TypeError: can only concatenate str (not "int") to str

this error showed up when i wrote:
NUMBER = int(input())
a = (NUMBER - 1)
b = (NUMBER + 1)
print ("The next number for the number" + (NUMBER) + "is" + (b))
print ("The previous number for the number" + (NUMBER) + "is" + (a))

You are viewing a single comment. View All
RyanRana (182)

What mwilki said was partially correct. For every integer item in the print stantment, you need to turn it into a string in order to get it in the same format as the rest of the strings. This is very easy to do.

print ("The next number for the number" + str(NUMBER) + "is" + str(b))
print ("The previous number for the number" + str(NUMBER) + "is" + str(a))

mwilki did this only with NUMBER, not with a & b. these two variables are based on the NUMBER variable, so they are integers to.

What lesson to take away from this: Whenever dealing with different types of data in python you always want to convert it to one. In this case, we converted NUMBER, a, and b to strings to print it out. But anyway just copy the code above into yours.

Also: Check out my programming youtube channel https://www.youtube.com/channel/UCIta8OqsKjfE1knTU2DJlSQ?disable_polymer=true
Please subscribe, python lessons beginner, intermediate, and advanced are included + projects!

Upvote this post if it helped!