You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a = 5
b = 6
def divide_test(a,b):
try:
print(a / b)
except TypeError:
print("Please provide numbers")
except ZeroDivisionError:
print("You cannot divide by zero!")
divide_test(4,5)
divide_test(4,0)
divide_test(4,"asdf")
assert
Temperature = -1
assert (Temperature >= 0),"Colder than absolute zero!"
Custom Exception Classes
class StudentNumberError(Exception):
def __init__(self):
Exception.__init__(self,"Number of students should be non negetive integer")
class Batch:
def __init__(self, students):
if type(students) == int and students >= 0:
self.students = students
else:
raise StudentNumberError