-
Notifications
You must be signed in to change notification settings - Fork 4
/
Odd_Even.py
42 lines (35 loc) · 1.05 KB
/
Odd_Even.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def Odd_Even(Num):
if (Num % 2) == 0:
return 'even' # Even number
else:
return 'odd' # Odd number
def main():
while True:
print("Odd/Even Checker")
while True:
Num = input("Enter the number: ")
try:
Num = float(Num)
break
except:
print("Invalid input please try again!")
status = Odd_Even(Num)
print(f"{Num} is an {status} number.")
# Program looping
while True:
try:
Again = input(
"Do you want to run this feature again(y/n)? ").lower()
if Again in ['y', 'n']:
break
else:
raise Exception("Invalid input")
# ⬆ To raise an error so that except gets triggered
except Exception:
print("Invalid input please try again!")
if Again == 'y':
continue
else:
break
if __name__ == '__main__':
main()