The python builtin input function gives you a string, you have to convert it to a int using int(input(..))
#Converted string to int
var = int(input("Enter a number!"))
var1 = var % 2
if var1 > 0:
print("The entered number is odd")
else:
print("The entered number is even")
Then the output will look like
Enter a number!5
The entered number is odd
Enter a number!4
The entered number is even
Note that your code will break if you provide a string as an input here
Enter a number!hello
Traceback (most recent call last):
File "/Users/devesingh/Downloads/script.py", line 2, in <module>
var = int(input("Enter a number!"))
ValueError: invalid literal for int() with base 10: 'hello'
So you can do a try/except around conversion, and prompt the user if he doesn't give you an integer
var = None
#Try to convert to int, if you cannot, fail gracefully
try:
var = int(input("Enter a number!"))
except:
pass
#If we actually got an integer
if var:
var1 = var % 2
if var1 > 0:
print("The entered number is odd")
else:
print("The entered number is even")
else:
print("You did not enter a number")
The output will then look like
Enter a number!hello
You did not enter a number
Enter a number!4
The entered number is even
Enter a number!5
The entered number is odd
Looks much better now doesn't it :)
int()wrap aroundinput(..)makes the input read an integer. Also, the condition you need is justif var1:.printinstead of the expected 4-space indent?