Very new to python and trying to create a program which takes an inputed number and tells the user if the number is odd or even. I have part of it working, it takes an number and gives the correct output depending on weather its odd or even, but the problem is, if you enter anything but a number, the program dosn't recongise it and crashes the program.
My solution dosn't work and I don't understand the error message.
Enter any number above 0 45
Traceback (most recent call last):
line 5, in <module>
if not number.isdecimal():
AttributeError: 'int' object has no attribute 'isdecimal'
My implementation:
while True:
print()
number = int(input("Enter any number above 0 ")) # Ask user to input a number
if not number.isdecimal(): # Trying to get code to reject a input that is not a number instead of crashing the program
print()
print("Incorrect format, please enter numbers")
print()
else:
if number % 2 == 0: # Tell user inputed number is even if number is even
print()
print("That number is even!")
else:
print()
print("That number is odd!") # Tell user inputed number is odd if number is odd