Jul-03-2019, 11:55 AM
I am using custom exception in my program along with built in exceptions given by python.
My code is:
My code is:
class Error(Exception): pass class ValueTooSmallError(Error): pass class ValueTooLargeError(Error): pass # user guesses a number until he/she gets it right # you need to guess this number number = 10 while True: try: i_num = int(input("Enter a number between 1-10: ")) 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("Congratulations! You guessed it correctly.")here I want that if user by mistakes enters a string instead of number, it should give ValueError that is the built-in exception in python...how do i use it with custom defined error...I did try but not getting it...Thanx in advance