Python Practice 5
Python Practice 5
Q2) Write a function to verify that tuple is immutable this function takes any tuple as parameter.
Q6) Using python string formatting print a table on console like this:
. Write your custom exception class “MyExceptions” and use it with any other python program .
class MyExceptions(Exception):
pass
def verify_age(age):
if age < 18:
raise MyExceptions("Pahlebaalig ho jao!!")
else:
print("Badhai ho! Tum baalig ho!")
a = int(input("Umrabatao: "))
try:
verify_age(a)
except MyExceptions as e:
print("Gadbadhaigo!\nError:",e)
finally:
print("Chalo ji! Phirmulakathogi!")
Oops:
Q. You are given two complex numbers , and you have to print the result of their addition, subtraction,
multiplication, division and modulus operations, use classes for this, implement operator overloading.
Q. Write a class A and implement some methods (add, subtract, divide integers), write another class B
which inherits class A and call these 3 methods from class B object.
# for loop
print("For Loop")
for i in range(1, num):
print(i*2, end=" ")
print()
# while loop
print("While Loop")
i=1
while i< num:
print(i*2, end=" ")
i += 1