Help for odd number check app in phyton
Hello everyone. I'm trying to create a terminal that check the number if it's odd Console prints it's odd number or else prints it's even. I wrote the code like below: num = int(input("Enter your number:")) if num%2 == 0: print("it's even") else: print("it's odd") Here's my problem and question: If user enter invalid value like "W" Console shows the error. I want to do this: if user entered invalid value like "M" Console prints "please enter valid number". Is there any special function for that? *UPDATE*: I wrote the code like below it almost fixed. Only one problem: if user enter a 2 digit number like 25 it shows please enter valid number Fix code: num = input("Enter your number:") numbers = ("1", "2", "3", "4", "5", "6," "7", "8", "9") while True: if num not in numbers: print("enter valid number") num = input("Enter your number:") else: fnum = int(num) if fnum%2 ==0: print("it's even") break else: print("it's odd") break