Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Try Except Else Clause

# program to print the reciprocal of even numbers

try:
    num = int(input("Enter a number: "))
    assert num % 2 == 0
except:
    print("Not an even number!")
else:
    reciprocal = 1/num
    print(reciprocal)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Python #Try #Except #Else #Clause
ADD COMMENT
Topic
Name
8+7 =