So I was trying to write this code for this situation:
Write a program that reads an integer number and prints its previous and next numbers
To solve this I wrote a code that had two different variables, one for the previous number and one for the next number. It looked like this:
a = int(input())
previous = a - 1
next = a + 1
So I'm trying to print the entire statement "The number after 180(ex) is 179" in one line. To do this, I typed:
print ("the number after " + a + "is " + previous)
Whenever I try to test this, the server always states that I need to change 'str' to 'int'. I do not know what to do for this issue. I'm new. Help me please.
The problem here is you're trying to add a string type to an integer. You cannot add a string (a bunch of letters) and a number, because you just can't. To fix this, using the
str() function (short for
string), tell python to turn the numbers into a string. Try this:
print ("the number after " + str(a) + "is " + str(previous)). This is a simplified version of what's really going on here, so I recommend you look up about datatypes, it'll help you a lot!