10. Implementing real-time/technical applications using Exception handling. (divide by zero error, voter’s age validity, student mark range validation)
10. Implementing real-time/technical applications using Exception handling. (divide by zero error, voter’s age validity, student mark range validation) Program a=int(input("Entre a=")) b=int(input("Entre b=")) try: c = ((a+b) / (a-b)) #Raising Error if a==b: raise ZeroDivisionError #Handling of error except ZeroDivisionError: print ("a/b result in 0") else: print (c) Output Enter a=4 Enter b=4 a/b result in 0 Voter’s age validity a=int(input("Enter your age")) try: c = a #Raising Error if c<18: raise ValueError #Handling of error except ValueError: print ("not eligible for voting - enter above 18") else: print (c) Student ...
Comments
Post a Comment