Q:

Python exception handling program (Handling Type exception)

belongs to collection: Python Exception Handling Programs

0

Steps to handle type exception in Python:

  • Step 1: Take input from the user.
  • Step 2: If the entered number is not an integer, throw an exception.
  • Step 3: If the entered number is an integer, print the integer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to illustrate handling of type exception in Python

while True:
    try:
        num = int(input("Enter First Number: "))
        print(num)
        break
    except ValueError as e:
        print("Invalid Input..Please Input Integer Only..")

Output:

Run 1: 
Enter First Number: 43
43

Run 2:
Enter First Number: 123.1
Invalid Input..Please Input Integer Only..
Enter First Number: 43
43

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program to illustrate importing exception f... >>
<< Python exception handling program (Handling divide...