0% found this document useful (0 votes)
9 views

Level 016

This document contains Python code examples demonstrating exception handling in Python. It shows try, except, else, raise and assert statements used to handle errors and exceptions that may occur during arithmetic operations or input validation.

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Level 016

This document contains Python code examples demonstrating exception handling in Python. It shows try, except, else, raise and assert statements used to handle errors and exceptions that may occur during arithmetic operations or input validation.

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

#!

python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result, end="\
n\n"))
input("Press Enter to Continue...")

https://www.tutorialspoint.com/python/python_exceptions.htm
https://www.programiz.com/python-programming/exception-handling
https://www.programiz.com/python-programming/exceptions
https://www.pythonforbeginners.com/error-handling/exception-handling-in-python
https://en.wikibooks.org/wiki/Python_Programming/Exceptions
https://en.wikibooks.org/wiki/Python_Programming/Exceptions
https://www.datacamp.com/community/tutorials/exception-handling-python
https://www.datacamp.com/community/tutorials/exception-handling-python#zero
https://www.javatpoint.com/python-exception-handling#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
if inValue02 == 0 :
print("\nDenominator Cannot Be Zero, Division Cannot Be Continued", end="\n\
n")
else :
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result,
end="\n\n")

input("Press Enter to Continue...")

#! python3

import os
os.system("cls")

print (" ")


print ("Illustrtaion of Simple \"if\" With A Value in Variable in Python")
print ("------------------------------OoO-------------------------------", end =
"\n")
inAge = int(input("\nPlease Enter Your Current Age : "))

print ("\nGiven Age is : ", inAge, "Years", end = "\n")

if inAge >= 12 and inAge <= 18 :


print ("\nSorry! You Are Not Eligible For Employment", end = "\n")
print ("\nYou Have To Wait For More : ", (18 - inAge), " Years.", end = "\n")
else :
print ("\nCongratulations! You Are Eligible For Employment, Please Forward
Your Resume", end="\n")

print ("\nCurrently We Are Out of The \"if\" Branch, Operating in The Main Stream
of The Program", end = "\n")#! python3

import os
os.system("cls")

print (" ")


print ("Illustrtaion of Simple \"if\" With A Value in Variable in Python")
print ("------------------------------OoO-------------------------------", end = "\
n")

inAge = int(input("\nPlease Enter Your Current Age : "))

print ("\nGiven Age is : ", inAge, "Years", end="\n")

if inAge >= 12 and inAge <= 18 :


print ("\nSorry! You Are Not Eligible For Employment", end = "\n")
print ("\nYou Have To Wait For More : ", (18 - inAge), " Years.", end = "\n")
raise Exception("Age Should be Above 18 Years. The Value of Age Found Was :
{}".format(inAge))
else :
print ("\nCongratulations! You Are Eligible For Employment, Please Forward
Your Resume", end = "\n")

print ("\nCurrently We Are Out of The \"if\" Branch, Operating in The Main Stream
of The Program", end = "\n")

#! python3

import os
os.system("cls")

print (" ")


print ("Illustrtaion of Simple \"if\" With A Value in Variable in Python")
print ("------------------------------OoO-------------------------------", end = "\
n")

inAge = int(input("\nPlease Enter Your Current Age : "))


assert (inAge >= 18), "Sorry! You Cannot Proceed as Age is Below 19"

print ("\nGiven Age is : ", inAge, "Years", end = "\n")

if inAge >= 12 and inAge <= 18 :


print ("\nSorry! You Are Not Eligible For Employment", end = "\n")
print ("\nYou Have To Wait For More : ", (18 - inAge), " Years.", end = "\n")
raise Exception("Age Should be Above 18 Years. The Value of Age Found Was :
{}".format(inAge))
else :
print ("\nCongratulations! You Are Eligible For Employment, Please Forward
Your Resume", end = "\n")

print ("\nCurrently We Are Out of The \"if\" Branch, Operating in The Main Stream
of The Program", end = "\n")#! python3

import sys
assert ('win32' in sys.platform), "This Code Runs Only on Windows Machine."

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result, end="\
n\n")
input("Press Enter to Continue...")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end = "\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")

try :
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result,
end = "\n\n")
except ZeroDivisionError :
print("\nDenominator Cannot Be Zero, Division Cannot Be Continued", end="\n\
n")

input("Press Enter to Continue...")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end = "\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))
print ("\nApplying The Division Operation For Quotient")
print ("-----------------------OoO-------------------------", end="\n\n")

try :
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result,
end="\n\n")
except ZeroDivisionError :
print("\nDenominator Cannot Be Zero, Division Cannot Be Continued", end="\n\
n")
else :
print ("Operation Completed Successfully, Continuing With The Next Level
Task", result, end="\n\n")

input("Press Enter to Continue...")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The Required Value : "))

import math
print("\nThe Exponentiation Calculated For ", inValue01, " is : ",
math.exp(inValue01), end = "\n")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The Required Value : "))

try:
import math
print("\nThe Exponentiation Calculated For ", inValue01, " is : ",
math.exp(inValue01), end = "\n")
except OverflowError:
print("\nOverFlow Exception Raised. Please Cross Check With The Vendor", end
= "\n")
else:
print("\nExponentiation Calculation is Done Successfully...")

#! python3

import os
os.system("cls")

inNumber = int(input("\nEnter Any Number Between 1 and 10 : "))

print("\nThe Given Number is : ", inNumber, end = "\n")#! python3


import sys
import os
os.system("cls")

try :
inNumber = int(input("\nEnter Any Numerical Value : "))
print("\nThe Given Number is : ", inNumber, end = "\n")
except ValueError :
print("\nSorry! You Can Only Input Numbers, Value is Mismatching Cannot
Continue...", end = "\n")
sys.exit()
else :
print("\nOperation Done Successfully", end = "\n")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))
assert(inValue02 != 0), "Denominator Cannot Be Zero, Division Cannot Be Continued,
Program is Terminating..."

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result, end="\
n\n")
input("Press Enter to Continue...")

#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
if inValue02 == 0 :
raise Exception("Denominator Cannot Be Zero, Division Cannot Be Continued")
else :
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result,
end="\n\n")

input("Press Enter to Continue...")


#! python3

import os
os.system("cls")

print ("Illustration of The Python Arithematical Operators")


print ("----------------------------OoO--------------------------", end="\n\n")

inValue01 = int(input ("\nPlease Enter The First Number : "))


inValue02 = int(input ("\nPlease Enter The Second Number : "))

print ("\nApplying The Division Operation For Quotient")


print ("-----------------------OoO-------------------------", end="\n\n")
result = inValue01 / inValue02
print ("The Quotient of ", inValue01, " and ", inValue02, " is : ", result, end="\
n\n")
input("Press Enter to Continue...")

You might also like