forked from varunpilankar/Packt
-
Notifications
You must be signed in to change notification settings - Fork 91
/
ud_except.py
40 lines (28 loc) · 873 Bytes
/
ud_except.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
class Error(Exception):
"""Base Class of other exceptions"""
pass
class ValueTooSmallError(Error):
"""Raised when the input value is too small"""
pass
class ValueTooLargeError(Error):
"""Raised when the input value is too large"""
pass
#out main program
#user guesses a number until he/she is right
#you need to guess this number
number = 10
while True:
try:
i_num = int(input("Enter a number :"))
if i_num < number:
raise ValueTooSmallError
elif i_num > number:
raise ValueTooLargeError
break
except ValueTooSmallError:
print("This value is too small, try again!!")
print()
except ValueTooLargeError:
print("This value is too large, try again!!")
print()
print("Congratulation! You guessed it correctly.")