+ 2
What is the problem with this code? "Invalid syntax" but why? And how to fix it Thx
# Read an integer: # a = int(input()) # Print a value: # print(a) a = input("type in the number") na = a + 1 pa = a - 1 print ("The next number from the number "+a+ "is "+na+". ") print ("The previous number from the number "+a+ "is "+pa+". ")
2 odpowiedzi
+ 3
You can't add int to string.
In your code, first make sure you read the input as int
a = int(input("enter your number:"))
Second in the print statment convert the int to string, as to concatenate the strings.
print("some text " + str(a) + ".")
Or just use comma instead of plus, and print make the conversion for you.
print("some text", a, ".")
- 1
The syntax error is because you don't close the parentheses in print