+ 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+". ")

25th Mar 2017, 8:22 AM
Annerb
Annerb - avatar
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, ".")
25th Mar 2017, 8:42 AM
Moataz El-Ibiary
Moataz El-Ibiary - avatar
- 1
The syntax error is because you don't close the parentheses in print
25th Mar 2017, 1:58 PM
Amaras A
Amaras A - avatar