Python Lab Record 2024
Python Lab Record 2024
Step 1 : Open a browser to the Python website and download the Windows installer.
Step 2 : Double click on the downloaded file and install Python for all users, and ensure that
Step 3 : Python is added to your path. Click on Install now to begin.
Step 4 : After the installation is complete, click Disable path length limit and then Close. Disabling
the path length limit means we can use more than 260 characters in a file path.
print("\nQ2. WAP in python to check out even number using if-else condition")
no =int(input("Enter a number: "))
if (no%2==0): print("\n Even Number")
else: print("\nOdd Number")
if x > 0:
print("\nPositive number")
elif x == 0:
print("\nZero")
else:
print("\nNegative number")
print("\nQ6. WAP in Python to find the largest number among the three numbers")
x = input("Enter first number: ")
y = input("Enter second number: ")
z = input("Enter third number: ")
if (x >= y) and (x >= z):
largest = x
elif (y >= x) and (y >= z):
largest = y
else:
largest = z
print("\nThe largest number is : ", largest)
#The infinite loop using while statement: If the condition of while loop is always True, we
get an infinite loop. # press Ctrl + c to exit from the loop
OUTPUT LAYOUT
OUTPUT LAYOUT
OUTPUT LAYOUT
OUTPUT LAYOUT
Q7. Programs using default arguments, recursions
# 1. Without parameters, without return statement
def fun():
print("\n\nWelcome to python function ")
fun()
# 2. With Parameters, without return statement
def hello(name):
print("\n Hello " + name)
hello("Anvi")
# 3. Without parameters, with the return statement
def isEven(x):
if (x % 2 == 0):
return "\n This number id Even"
else:
return "\n Not Even number"
even10 = isEven(10)
print(even10)
# 4. With parameters, with return statement
def sum(a, b):
return a + b
total=sum(10,20)
print("\nsum of a and b = ",total)
x = [5,10,15,20,25,30,40,50]
add_list(x)
print("\nOutside Function: ", x)
#Recursive Functions
def rec_sum(n):
if n<=1:
return n
else:
return n + rec_sum(n-1)
y = rec_sum(10)
print("sum of 1 to 10 =",y)
print("To find the factorial of an integer using recursions")
def factorial(n):
if n == 1:
return n
else:
return n*factorial(n-1)
num = 5
# check if the number is negative
if num < 0:
print("factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is",factorial(num))
OUTPUT LAYOUT
class Employee:
# class variables
dept = 'Marketing'
# instance method
def show(self):
print('\nEmployee:', self.name, self.salary, self.dept)
# instance Method
def show(self):
print('Welcome, my name is', self.name)
# create object using constructor
s1 = Student('Anvi Anwesha')
s1.show()
class Parent:
def __init__(self , name, roll):
self.fname = name
self.rollno = roll
def view(self):
print(self.fname , self.rollno)
class Child(Parent):
def __init__(self , name , roll):
Parent.__init__(self, name, roll)
self.lname = "Ray"
def view(self):
print("\nRoll No:", self.rollno ,"\n Name : " , self.fname , "\n Last Name: " , self.lname, "
\nDept of IST, \nRavenshaw University\nCuttack")
ob = Child("Anvi Anwesha" , '2023')
ob.view()
#Create a Bus child class that inherits from the Vehicle class. The default fare charge of any vehicle
is seating
#capacity * 100. If Vehicle is Bus instance, we need to add an extra 10% on full fare as a
maintenance charge.
#So total fare for bus instance will become the final amount = total fare + 10% of the total fare.
class Vehicle:
def __init__(self, name, mileage, capacity):
self.name = name
self.mileage = mileage
self.capacity = capacity
def fare(self):
return self.capacity * 100
class Bus(Vehicle):
pass
OUTPUT LAYOUT
Q9. Programs of Method Overriding, operator overloading, the super() method,
MRO, interfaces.
class ITM(IST):
def show(self):
print("\nHello, I am in Department of ITM")
print("\nMethod overriding in Python is when you have two methods with the same name that
each perform different tasks.")
r =ITM()
r.show()
r = IST()
r.show()
class Computer():
def __init__(self, computer, ram, storage):
self.computer = computer
self.ram = ram
self.storage = storage
class Mobile(Computer):
def __init__(self, computer, ram, storage, model):
super().__init__(computer, ram, storage)
self.model = model
class B:
pass
c = C()
c.method()
import abc
class Myi_face( abc.ABC ):
def disp( ):
pass
class Mydemo(Myi_face):
def disp(s):
print("\nThis is the Interface programming example. ")
o1=Mydemo()
o1.disp()
OUTPUT LAYOUT
class VotingPerson(Exception):