Program: Information Technology (314319) Semester: IV
Course:- Python Programming Course Code: 314004
LIST OF LABORATORY PRACTICALS
Academic Year: 2024-25
1. Implement the python program to read data from user and display data on screen.
name=input("enter your name=")
age=int(input("enter the age="))
print("hello",name)
print("age=",age)
2. Implement a python programs using following operators:
i. Arithmetic
ii. Relational & logical
iii. Assignment
iv. Bitwise
v. Membership
vi. Identity
#arithmetic
a=10
b=5
print("add=",a+b)
print("sub=",a-b)
print("mul=",a*b)
print("div=",a/b)
print("power=",a**b)
print("floor=",a//b)
print("modules=",a%b)
#realational and logical
x=20
y=10
print("equual=",x==y)
print("logical and=",x>2 and y<=12)
print("logical or=",x>2 and y<=12)
print("lofical not=",not(x>5))
#assignment
p=10
p+=5
print("p after+5=",p)
q=12
q*=2
print("q after *=",q)
#bitwise
a=4
b=2
print("bitwise and=",a&b)
print("bitwise or=",a|b)
print("bitwise not=",~a)
print("bitwise xor=",a^b)
print("bitwise left shift=",a<<2)
print("bitwise right shift=",a>>2)
#membership
list1=[10,12,20,30,40]
print("10 in list1=",10 in list1)
print("10 not in list1=",10 not in list1)
#identity
x=[1,2,3]
y=x
z=[1,2,3]
print("x is y",x is y)
print("x is z",x is z)
print("x==z",x==z)
3. Implement a python program to demonstrate the use of conditional statements.
age=int(input("enter the age"))
if age>=18:
print("you are adult")
elif age>12:
print("you are teeneger")
else:
print("you are child")
4. Implement a python program to demonstrate the use of looping statements.
//simple program
5. Implement a python program to perform following operations on the List:
Create a List, Access List, Update List, Delete List
my_list = [10, 20, 30]
print("Original List:", my_list)
print("Accessing:", my_list[1])
my_list[1] = 25
print("Updated List:", my_list)
del my_list[0]
print("List after deletion:", my_list )
6. WAP to find the sum of elements in a list.
numbers = [1, 2, 3, 4, 5]
print("Sum:", sum(numbers))
7. WAP to remove duplicates from a list
list1=[1,2,2,4,4,5]
uniq=list(set(list1))
print("list after removing",uniq)
8. Implement python program to perform following operations on the Tuple:
Create a List, Access List, Update List, Delete List
my_tuple = (1, 2, 3)
print("Tuple:", my_tuple)
print("Accessing:", my_tuple[1])
# Tuples are immutable, update not allowed
del my_tuple
9. WAP to convert list to tuple
my_list = [1, 2, 3]
my_tuple = tuple(my_list)
print("Tuple:", my_tuple)
10. Implement a python program to perform following operations on the Set:
[Link] a Set 2. Access Set 3. Update Set 4. Delete Set
my_set = {1, 2, 3}
print("Set:", my_set)
print("Accessing by loop:")
for item in my_set:
print(item)
my_set.add(4)
print("Updated Set:", my_set)
my_set.remove(2)
print("Set after deletion:", my_set)
11. Write a Python program to perform following operations on set: intersection of
sets, union of sets, set difference
a = {1, 2, 3}
b = {3, 4, 5}
print("Intersection:", a & b)
print("Union:", a | b)
print("Difference:", a – b)
12. Write a Python script to sort (ascending and descending) a dictionary by value.
dict1={'a':5,'b':1,'c':2}
print("ascending=",dict(sorted([Link](),key=lambda item:item[1])))
print("descending=",dict(sorted([Link](),key=lambda item:item[1],reverse=True)))
[Link] a Python program to find the highest 3 values in a dictionary.
d = {'a': 3, 'b': 8, 'c': 5, 'd': 10, 'e': 2}
highest = sorted([Link](), reverse=True)[:3]
print("Top 3 values:", highest)
14. Write a Python function that takes a number as a parameter and check the number
is prime or not.
def prime(n):
if(n<2):
return False
for i in range(2,n):
if(n%i==0):
return False
return True
num=int(input("enter the num:"))
if prime(num):
print("prime")
else:
print("not prime")
[Link] program to demonstrate use of variable length arguments.
def func(num,*list):
print(num)
for i in list:
print(i)
func(10,20,50,77,88,90)
[Link] Python program to Lambda Function using Square of a Number.
square=lambda x:x**2
num=int(input("enter the num:"))
result=square(num)
print("square of num:",result)
[Link] a Python program that demonstrates the use of the following modules:
a) Math module – Calculate the square root of a number.
import math
num=int(input("enter the num:"))
print("square =",[Link](num))
b) Random module – Generate a random number between 1 and 100.
import random as rd
num=[Link](1,100)
print(num)
18. Write a Python program to perform the following operations:
a) Create a class named Student with a method display_info() that prints the student's
name and age.
class student:
def __init__(self,name,age):
[Link]=name
[Link]=age
def display_info(self):
print("name=",[Link])
print("age=",[Link])
s=student("pratiksha",17)
s.display_info()
b) Create objects of the Student class with different values
class student:
def __init__(self,name,age):
[Link]=name
[Link]=age
def display_info(self):
print("name=",[Link])
print("age=",[Link])
s=student("pratiksha",17)
s.display_info()
s1=student("pratiksha",19)
s1.display_info()
19. Write a python program to calculate area of circle using inbuilt Math module.
import math
rad=int(input("enter the radius="))
area=[Link]*[Link](rad,2)
print("area of cir=",area)
20. Write a Python class to implement pow(x, n)
//method 1
class mat:
def power(self,x,n):
p=1
for i in range(n):
p=p*x
return p
m=mat()
p=[Link](2,4)
print("power=",p)
//method 2
[Link] a python program to demonstrate the use of constructors
a. Default
b. Parameterized
c. Constructor Overloading
class demo:
def __init__(self,name="Default"):
print("name=",name)
d1=demo()
d2=demo("pratu")
22. Write python program to demonstrate data hiding.
class secreat:
def __init__(self):
self.__secreatnum="this is hidden var"
def get_var(self):
return self.__secreatnum
s=secreat()
print("hide=",s.get_var())
23. Write a python program to implement the following inheritance in 2 different
Programs.
a. Single inheritance
b. Multiple Inheritance
#single
class student:
def get_data(self,name,age):
[Link]=name
[Link]=age
def put_data(self):
print("name=",[Link])
print("age=",[Link])
class dept(student):
def get_val(self,dept_n):
self.dept_n=dept_n
def put_val(self):
print("dept=",self.dept_n)
d=dept()
d.get_data("pratiksha",17)
d.put_data()
d.get_val("co")
d.put_val()
#multiple inheritance
class a:
def first(self):
print("class a")
class b:
def second(self):
print("class b")
class c(a,b):
pass
c1=c()
[Link]()
[Link]()
24. Implement Python program to perform following operations using panda package:
a. Create Series from Array
b. Create Series from List
c. Access element of series
import pandas as pd
import numpy as np
a=[Link]([10,20,30])
res=[Link](a)
print("series using array=",res)
#import pandas as pd
list1=[10,30,89]
res1=[Link](list1)
print("series in list=",res1)
print("first list serires=",res1[0])
[Link] to Create Data Frame using List or dictionary.
import pandas as pd
'''
data1=[[10,20,30],[20,30,40]]
res=[Link](data1)
print(res)'''
data_dict={"name":["alice","bob"],"age":[12,17]}
res=[Link](data_dict)
print(res)
[Link] python GUI program to import Tkinter package and create a window and set its
title.
import tkinter as tk
root= [Link]()
[Link]("tkinter window")
[Link]("500x500")
[Link]()
[Link] to find the factorial of the number.
num=int(input("enter the fact="))
fact=1
for i in range(1,num+1):
fact=fact*i
print("fact=",fact)
[Link] to connect connection between Database and Python.
import sqlite3
conn=[Link]("[Link]")
print("database connected")
[Link]()
[Link] a python program to demonstrate
a) Method Overloading
class shape:
def area(self,length,breadth=None):
if breadth is None:
print("area of square=",length*length)
else:
print("area of rect=",length*breadth)
s=shape()
[Link](5)
[Link](10,5)
b)Method Overriding
class parent:
def show(self):
print("parent")
class child(parent):
def show(self):
print("child")
c=child()
[Link]()
30. Implement python program to select records from the database table and display the
result.