Exp 10 python

0

 Create a program that prompts the user for two numbers and then divides them, handling any exceptions that may arise. 



while True:

    try:

        num1 = float(input("Enter the first number: "))

        num2 = float(input("Enter the second number: "))

        

        result = num1 / num2

        print("Result of division:", result)

        break # Exit the loop if division is successful

    except ValueError:

        print("Please enter valid numbers.")

    except ZeroDivisionError:

        print("Cannot divide by zero. Please enter a non-zero second number.")

Post a Comment

0Comments

GUYS IF YOU HAVE ANY DOUBT. PLEASE LET ME KNOW

Post a Comment (0)