You are on page 1of 17

EXERCISE 1 String Operations u+=1

word="ATOMIC" if s[i].islower():
print(word[0:6]) l+=1
print(word[2:5]) print('No of Upper Case characters',u)
print(word[2:4]) print('No of Lower Case characters',l)
print(word[:6]) EXERCISE 4 LIST Operations
print(word[2:]) a=[10,20,30,40,50]
print(word[0:6:2]) print(a,a[3],a[-4])
print(word[::2]) a=['A','T','O','M','I','C']
print(word[-6:-1]) print(a,a[3],a[-4])
print(word[-5:-2]) a=[10,20,[30,40],50]
print(word[-6:-1:3]) print(a,a[2],a[-4])
print(word[:-3]) b=[60]
print(word[::-2]) print(a>b,a==b,a+b)
print(ord('A')) a=[10,20,30,40,50,60]
print(chr(65)) print(a,a[1:4],a[1:-2])
print(len(word)) print(a[::-2])
EXERCISE 2 String Functions a[0:2]=['ten','twenty']
a='Atomic' print(a)
b='Energy' a[1:]='987'
print(a+b) print(a)
print(a*3) EXERCISE 5 LIST Functions
print('w' in a) a=list('123456')
print('w' not in a) print(a)
word='ATOMIC ENERGY CENTRAL SCHOOL' b=list('Atomic')
s='CENTRAL' print(b)
print(word.find(s)) a=list('5+8')
print(word.find(s,15,22)) print(a)
print(word.find(s,0,22)) b=eval('5+8')
print(s.isalnum()) print(b)
print(s.isalpha()) a=(10,20,30,40,50)
print(s.isupper()) print(a)
print(s.isdigit()) b=list(a)
print(" ".isspace()) print(b)
print(s.lower()) c=b
print(s.rstrip('AL')) print(c)
print(s.lstrip('CE')) print(min(c),max(c),c.index(30))
print(s.lstrip()) c.append(60)
c='-' print(c)
print(c.join(s)) c.insert(1,15)
print(s.swapcase()) print(c)
print(word.partition('ENERGY')) d=[70,80,90]
print(word.partition(' ')) c.extend(d)
EXERCISE 3 Count No of Upper and Lowercase print(c)
characters in a string y=c.pop()
s=input('Enter String :') print("popped item",y)
u=l=0 print(c)
for i in range (0,len(s)): d.clear()
if s[i].isupper(): print(d)
S.K,Mukherjee 1
print(c.count(20)) print(d)
c.remove(40) print("Length :",len(d))
print(c) for i in d:
c.sort() print(i,"Book costs Rs.",d[i])
print(c) l=list(d.keys())
c.reverse() print(l)
print(c) t=tuple(d.values())
s=sum(c) print(t)
print(s) d['Java']=550
del(c) print(d)
text="ATOMIC ENERGY CENTRAL SCHOOL" d['HTML']=250
print(text.split()) print(d)
EXERCISE 6 TUPLE Functions del d['Oracle']
a=tuple('123456') print(d)
print(a) d.pop('C++')
b=('A','t','o','m','i','c') print(d)
print(b,b[0]) print(d.pop('Spider','Book Not found'))
a=tuple('5+8') print(json.dumps(d,indent=2))
print(a) print(d.get('python'))
b=eval('5+8') seq=d.items()
print(b) for k,v in seq:
a,b=(10,20,30,40,50),(10,20,30,40,50) print(k,v)
print(a<b) d1={"FORTRAN":300,"COBOL":275}
a,b=(10,20),(10.0,20.0) d.update(d1)
print(a==b) print(d)
print(a+b,a*2) EXERCISE 9 Dict Student information
a=(10,20,30,40,50,60,70,80,90,100) d={}
print(a) n=int(input('Enter no of students:'))
print(a[1:4],a[2:-6],a[1:7:2]) for i in range(n):
b=a[::-2] rno=int(input('Enter Rollno:'))
print(b) name=input('Enter Name :')
a=a+(110,120) mark=int(input('Enter Mark :'))
print(a) l=[name,mark]
print(len(a),max(a),min(a),a.index(50)) d[rno]=l
EXERCISE 7 : FIBONACCI SERIES USING print(d)
FUNCTION x=int(input('Enter Student Rollno :'))
def fibo(n): print(d[x])
a,b=-1,1 EXERCISE 10 Built in functions
for i in range(n): import math
c=a+b print(abs(-7))
print(c,end=” “) print(all(['test','','a']))
a=b print(any(['test','','a']))
b=c print(bin(7) , hex(15),oct(8))
n=int(input('Enter no of terms of the Fibonacci print(int('7'))
Series')) print(bool(0.5))
fibo(n) print(chr(65) , ord('A'))
EXERCISE 8 DICTIONARY Functions print(complex(3))
import json print(divmod(7,3))
d={"python":500,"C++":400,"Java":450,"Oracle":800} x=7
S.K,Mukherjee 2
print(eval('x+7')) fact_wor(a))
exec('a=2;b=3;print(a+b)') EX 14 Calculator using MODULE
print("a={a} and b={b}".format(a=3,b=4)) example.py
print(len({1,2,2,3})) def add(a, b):
print(max(2,3,4),min(2,3,4)) result = a + b
print(round(3.777,2),round(377.77,- return result
1),math.ceil(100.1),math.floor(- def sub(a, b):
45.8),math.log10(100)) result = a - b
print(set([2,2,3,1])) return result
print('Python'[slice(1,5,2)]) def mul(a, b):
print(sorted('python')) result = a * b
print(sum([3,4,5],2)) return result
EXERCISE 11 math , random modules def div(a, b):
import math result = a / b
import random return result
print(math.comb(5, 4))
print(math.factorial(6)) a.py
print(math.fmod(5,3)) import example
print(math.gcd(10,20)) print('1. Add')
print(math.trunc(12.9)) print('2. Subtract')
print(math.dist((1,2), (2,5))) print('3. Multiply')
print(math.hypot(4,5)) print('4. Divide')
print(math.degrees(3.14),math.radians(180)) a=int(input('Enter a :'))
print(math.acosh(90)) b=int(input('Enter b :'))
print(random.random(),random.random()*10) ch=int(input('Enter Choice:'))
print(random.randint(2,6)) if ch==1:
print(random.randrange(1,7,2)) print(example.add(a,b))
EXERCISE 12 local and global variables if ch==2:
def func(b): print(example.sub(a,b))
global a if ch==3:
a=a+5 print(example.mul(a,b))
print(a,b) if ch==4:
a=10 print(example.div(a,b))
func(20) EX 15 linear search
print (a) def lsearch(l,x):
EX 13 Factorial fn with/without return for i in range(len(l)):
def fact_wr(n): if l[i]==x:
f=1 print('Element found
for i in range(2,n+1): at',i+1)
f*=i break
return f else:
def fact_wor(n): print('Not found')
f=1 l=[12,45,65,-89,-62,52,79]
for i in range(2,n+1): print(l)
f*=i x=int(input('Enter the element to be searched:'))
print(f) lsearch(l,x)
EX 16 BINARY search
a=int(input('Enter a no')) def binary_search(arr, x):
print(fact_wr(a)) low = 0
S.K,Mukherjee 3
high = len(arr) - 1 import random
mid = 0 n=int(input('Enter no of elements:'))
list1=[]
while low <= high: list1=random.sample(range(1,100),n)
print('Original List',list1)
mid = (high + low) // 2 print('Sorted List:',isort(list1))
if arr[mid] < x: Ex19: area using module
low = mid + 1
elif arr[mid] > x: area.py
high = mid - 1 def circle(r):
else: return 3.14*r*r
return mid def rectangle(l,b):
return -1 return l*b

arr = [ 12, 3, -44, -78, 91,56,5,-20 ] a.py


arr.sort() import area
print(arr) r=float(input('Enter radius :'))
x = int(input('Enter the item to be searched')) l=int(input('Enter length :'))
result = binary_search(arr, x) b=int(input('Enter breadth: '))
if result != -1: print('Area of the circle =',area.circle(r))
print("Element is present at index", str(result)) print('Area of the rectangle=',area.rectangle(l,b))
else: Ex20: package
print("Element is not present in array")  Create a folder inside python folder
EX17. Bubble sort  Create an empty __init__.py file inside the
def bubble(l): folder you created.
for i in range(len(l)):  Create two modules called area.py and
for j in range(len(l)-1): volume.py inside that folder
if l[j]>=l[j+1]:  From python folder create a file called a.py and
l[j],l[j+1]=l[j+1],l[j] use the package
print('Sorted List')
print(l) area.py
import random def square(a):
n=int(input('Enter no of elements:')) return a*a
l=[] def rectangle(l,b):
l=random.sample(range(1,100),n) return l*b
print('Original List')
print(l) volume.py
bubble(l) def cube(a):
EX :18 Insertion Sort return a*a*a
def isort(list1): def cuboid(l,b,h):
for i in range(1, len(list1)): return l*b*h
value = list1[i] a.py
j=i-1 from SKM import area,volume
while j >= 0 and value < list1[j]: print(area.rectangle(10,20))
list1[j + 1] = list1[j] print(volume.cube(20))
j -= 1 Ex:21 file read,readline and readlines
list1[j + 1] = value with open('sample.txt','w') as f:
return list1 f.write('''Welcome to the world of
computers
S.K,Mukherjee 4
Lets learn the art of python programming Ex24:Count the vowels in a file and write in the
Python with MYSQL helps you build you a file itself
successful career''') with open('sample.txt','w') as f:
with open('sample.txt','r') as f: f.write('''Welcome to the world of
print(f.read()) computers
with open('sample.txt','r') as f: Lets learn the art of python programming
print(f.read(7)) Python with MYSQL helps you build you a
with open('sample.txt','r') as f: successful career''')
print(f.readline())
with open('sample.txt','r') as f: with open("sample.txt", "r") as f:
data=f.readlines() data=f.read()
print(data) v=0
Ex22: copy contents of one file to another line by for i in data:
line if i in ('a','e','i','o','u'):
with open('sample.txt','w') as f: v+=1
f.write('''Welcome to the world of with open('sample.txt','a') as f:
computers f.write(' Total no of vowels:')
Lets learn the art of python programming f.write(str(v))
Python with MYSQL helps you build you a
successful career''') with open('sample.txt','r') as f:
print(f.read())
f1 = open("sample.txt", "r") Ex25: Count the upper and lower case characters
f2 = open("sample1.txt", "w") in a file and write in the file itself
for line in f1: with open('sample.txt','w') as f:
f2.write(line) f.write('''Welcome to the world of
f1.close() computers
f2.close() Lets learn the art of python programming
Python with MYSQL helps you build you a
with open('sample1.txt','r') as f: successful career''')
print(f.read())
Ex23: copy contents of one file to another by with open("sample.txt", "r") as f:
capitalizing each word data=f.read()
with open('sample.txt','w') as f: l=u=0
f.write('''Welcome to the world of for i in data:
computers if i.islower():
Lets learn the art of python programming l+=1
Python with MYSQL helps you build you a if i.isupper():
successful carrer''') u+=1
with open('sample.txt','a') as f:
f1 = open("sample.txt", "r") f.write(' Total no of Lower Case:')
f2 = open("sample1.txt", "w") f.write(str(l))
str=f1.read() f.write(' Total no of Upper Case:')
res=' '.join(i.capitalize() for i in str.split()) f.write(str(u))
f2.write(res)
f1.close()
f2.close() with open('sample.txt','r') as f:
with open('sample1.txt','r') as f: print(f.read())
print(f.read()) Q26. Count the alphabets , digits and special
characters in a file and write in the file itself

S.K,Mukherjee 5
print(c)

with open('sample.txt','w') as f: with open('sample.txt','r') as f:


f.write('''Welcome to the world of print(f.read())
computers!!! Ex28: To store random number in a list in the file
Lets learn the art of python 3.8 programming and store it the file after sorting.
Python with #MYSQL helps you build you a
successful career''') import random
with open('sample.txt','w') as f:
with open("sample.txt", "r") as f: l=[random.randint(0,100) for i in range(10)]
data=f.read() print(l)
l=u=s=0 l.sort()
for i in data: for i in l:
if i.isalpha(): f.write(str(i))
l+=1 f.write(' ')
elif i.isdigit():
u+=1 with open('sample.txt','r') as f:
else: print(f.read())
s+=1 Ex29: write and read a record in a binary file.
with open('sample.txt','a') as f:
f.write(' Total no of alphabets: ') import pickle
f.write(str(l)) list =[]
f.write(' Total no of digits :') while True:
f.write(str(u)) roll = input("Enter student Roll No:")
f.write(' Total no of Spl Characters :') sname = input("Enter student Name :")
f.write(str(s)) student = {"roll":roll,"name":sname}
list.append(student)
with open('sample.txt','r') as f: choice= input("Want to add more record(y/n) :")
print(f.read()) if(choice=='n'):
break
Q27. To count the particular word from a file and
display over the screen. with open("student.dat","wb") as f:
pickle.dump(list,f)
with open('sample.txt','w') as f: with open("student.dat","rb") as f:
f.write('''Welcome to the world of data=pickle.load(f)
computers!!! print(data)
Lets learn the art of python 3.8 programming Q30. Store student information(marks,
Python with #MYSQL helps you build you a name,age{dicitionary}) in a binary file and print.
successful career''')
import pickle
with open("sample.txt", "r") as f: list =[]
data=f.read() while True:
data=data.split() sname = input("Enter student Name :")
word=input('Enter the word to be searched smark = int(input('Enter the mark:'))
:') age = input('Enter Date of Birth
c=0 DDMMMYYYY')
for i in data: d = age[0:2]
if word in i: m =age[2:5]
c+=1 y = age[5:9]
S.K,Mukherjee 6
student = d.writerow([1, "Linus Torvalds", "Linux Kernel"])
{"name":sname,"mark":smark,"age":{"day":d,"month d.writerow([2, "Tim Berners-Lee", "World Wide
":m,"year":y}} Web"])
list.append(student) d.writerow([3, "Guido van Rossum", "Python
choice= input("Want to add more record(y/n) :") Programming"])
if(choice=='n'):
break with open('student.csv', 'r') as f:
d = csv.reader(f)
with open("student.dat","wb") as f: x=sum(1 for line in f)
pickle.dump(list,f) print('No of Records:',x-1)
with open("student.dat","rb") as f: Ex33: to print a record of a particular student from
data=pickle.load(f) CSV file
print(data)
EX31:Fetch a particular student info from the import csv
binary file(ref. prev prob) with open('student.csv', 'w',newline='') as f:
import pickle d = csv.writer(f)
import json d.writerow(["SN", "Name", "Subject"])
d ={} d.writerow([1, "Linus Torvalds", "Linux Kernel"])
while True: d.writerow([2, "Tim Berners-Lee", "World Wide
sname = input("Enter student Name :") Web"])
smark = int(input('Enter the mark:')) d.writerow([3, "Guido van Rossum", "Python
age = input('Enter Date of Birth Programming"])
DDMMMYYYY')
d = age[0:2] with open('student.csv', 'r') as f:
m =age[2:5] d=csv.reader(f)
y = age[5:9] x=int(input('Enter SN to be searched:'))
student = for i in d:
{"name":sname,"mark":smark,"age":{"day":d,"month if i[0]==str(x):
":m,"year":y}} print('Name : ',i[1],'Subject :',i[2])
print(student) Ex34: Basic Operations of stack
choice= input("Want to add more record(y/n) :") def Push(stk,n):
if(choice=='n'): stk.append(n)
break def Pop(stk):
if (stk==[]):
with open("student.dat","wb") as f: print('Stack Empty')
pickle.dump(student,f) else:
print('Deleted element',stk.pop())
with open("student.dat","rb") as f: def Display(stk):
data=pickle.load(f) print(stk)
name=input("Enter student Name :")
for i in data.values(): Stack=[]
if i == name : while True:
print(data.values()) print()
print("1.PUSH")
Ex32:count no of records in a csv file print("2.POP")
import csv print("3.DISPLAY")
with open('student.csv', 'w',newline='') as f: print("4.EXIT")
d = csv.writer(f) ch=int(input('Enter your choice'))
d.writerow(["SN", "Name", "Subject"]) if (ch==1):
S.K,Mukherjee 7
a=input("Enter any number") ename=input("Enter Employee
Push (Stack,a) Name:")
elif (ch==2): d[eno]=ename
Pop (Stack) elif (ch==2):
elif (ch==3): d.popitem()
Display (Stack) elif (ch==3):
else: print(d)
break else:
Q35:Opeations in a Queue break
def Push(Q,n): Ex37: Program to add, delete and display the
Q.append(n) records of an employee using list (contains eno,
def Pop(Q): ename) implementation through QUEUE.
if (Q==[]):
print('Queue Empty') d={}
else: while True:
print('Deleted element',Q.pop(0))
print()
def Display(Q):
print("1.Add Employee Data")
print(Q)
print("2.Delete Employee Data")
Queue=[] print("3.View Employee Data")
while True: print("4.EXIT")
print("1.PUSH") ch=int(input('Enter your choice'))
print("2.POP") if (ch==1):
print("3.DISPLAY")
eno=input("Enter Employee No:")
print("4.EXIT")
ch=int(input('Enter your choice')) ename=input("Enter Employee
if (ch==1): Name:")
a=input("Enter any number") d[eno]=ename
Push (Queue,a) elif (ch==2):
elif (ch==2): l=list(d.keys())[0]
Pop (Queue) d.pop(l,'not found')
elif (ch==3):
elif (ch==3):
Display (Queue)
else: print(d)
break else:
Q36: Program to add, delete and display the break
records of an employee using list (contains eno,
ename) implementation through stack. Ex 38: Write a FUNCTION to add, delete and
display the records of an employee using queue
d={} (contains eno, ename) implementation through
while True: queue.
print()
print("1.Add Employee Data") def qadd():
print("2.Delete Employee Data") eno=input("Enter Employee No:")
print("3.View Employee Data") ename=input("Enter Employee Name:")
print("4.EXIT") d[eno]=ename
ch=int(input('Enter your choice'))
if (ch==1): def qdel():
eno=input("Enter Employee No:") l=list(d.keys())[0]
S.K,Mukherjee 8
d.pop(l,'not found') cur.execute("insert into employee
def qview(): values(423,'ISHA','UCIL
print(d) COLONY','COM','TEACHER','M','8764440747',5500
0)")
d={} cur.execute("insert into employee
while True: values(523,'KUMAR','KOLKATA','CSC','SCHOLAR
print() ','M',null,null)")
print("1.Add Employee Data") cur.execute('select * from employee')
print("2.Delete Employee Data") for i in cur:
print("3.View Employee Data") print(i)
print("4.EXIT") sql='alter table employee add(loc varchar(3))'
ch=int(input('Enter your choice')) cur.execute(sql)
if (ch==1): cur.execute('desc employee')
qadd() for i in cur:
elif (ch==2): print(i)
qdel() cur.execute('update employee set loc="JAD" where
elif (ch==3): deptcode="CSC"')
qview() cur.execute('select * from employee')
else: for i in cur:
break print(i)
Ex:39
import mysql.connector cur.execute('select distinct deptcode from employee
db=mysql.connector.connect(host='localhost',user=' order by deptcode desc')
root',password='mysql') for i in cur:
cur=db.cursor() print(i)

cur.execute('drop database if exists sample') cur.execute('select count(*),deptcode from


cur.execute('create database sample') employee group by deptcode')
cur.execute('use sample') for i in cur:
cur.execute('drop table if exists employee') print(i)
cur.execute('''create table employee (empcode int
primary key,
empname varchar(25), address varchar(50), cur.execute('delete from employee where empname
deptcode varchar(3), like "VI%"')
designation varchar(15), gender char(1), mobile cur.execute('select * from employee')
varchar(10), basicsalary decimal(10,2))''')
cur.execute('desc employee') for i in cur:
for i in cur: print(i)
print(i)
cur.execute("insert into employee cur.execute('commit')
values(123,'SKM','UCIL db.close()
COLONY','CSC','TEACHER','M','9869071856',75052 Ex40:
.50)") import mysql.connector
cur.execute("insert into employee db=mysql.connector.connect(host='localhost',user='
values(223,'GARIMA','KOLKATA','BIO','STUDENT root',password='mysql')
','M','886907165819',0)") cur=db.cursor()
cur.execute("insert into employee
values(323,'BABU','TATA cur.execute('drop database if exists sample')
NAGAR','ART','STUDENT','F',null,0)") cur.execute('create database sample')

S.K,Mukherjee 9
cur.execute('use sample') cur.execute('select * from student')
cur.execute('show databases') for i in cur:
for i in cur: print(i)
print(i)
cur.execute('delete from student where rollno=3')
db.close() cur.execute('select * from student')
Ex 41 to 47 : for i in cur:
import mysql.connector print(i)
db=mysql.connector.connect(host='localhost',user='
root',password='mysql') cur.execute('update student set age=17 ')
cur=db.cursor() cur.execute('update student set age=18 where
gender="M"')
cur.execute('drop database if exists sample') cur.execute('select * from student')
cur.execute('create database sample') for i in cur:
cur.execute('use sample') print(i)
cur.execute('drop table if exists student')
cur.execute('''create table student (rollno int
primary key, cur.execute('commit')
sname varchar(25), address varchar(50), deptcode db.close()
varchar(3), Ex :48
gender char(1), mobile varchar(10))''') import mysql.connector
cur.execute('desc student') db=mysql.connector.connect(host='localhost',user='
for i in cur: root',password='mysql')
print(i) cur=db.cursor()
cur.execute("insert into student cur.execute('use sample')
values(1,'SKM','UCIL cur.execute('select * from student')
COLONY','CSC','M','9869071856')") for i in cur:
cur.execute("insert into student print(i)
values(2,'GARIMA','KOLKATA','BIO','M','88690716 try :
5819')") name=input('Enter student name:')
cur.execute("insert into student sql='delete from student where sname LIKE
values(3,'BABU','TATA NAGAR','ART','F',null)") '+"'"+name+"'"
cur.execute("insert into student cur.execute(sql)
values(4,'ISHA','UCIL except:
COLONY','COM','M','8764440747')") db.commit()
cur.execute("insert into student
values(5,'KUMAR','KOLKATA','CSC','M',null)") cur.execute('select * from student')
cur.execute('select * from student') for i in cur:
for i in cur: print(i)
print(i) db.close()
s='alter table student add(mark int(3), age int(2))'
cur.execute(s) OUTPUT
EX1:
s='alter table student modify address varchar(35)' ATOMIC
cur.execute(s) OMI
cur.execute('desc student') OM
for i in cur: ATOMIC
print(i) OMIC
AOI

S.K,Mukherjee 10
AOI [10, 20, 30, 40, 50]
ATOMI 10 50 2
TOM [10, 20, 30, 40, 50, 60]
AM [10, 15, 20, 30, 40, 50, 60]
ATO [10, 15, 20, 30, 40, 50, 60, 70, 80, 90]
CMT popped item 90
65 [10, 15, 20, 30, 40, 50, 60, 70, 80]
A []
6 1
EX2: [10, 15, 20, 30, 50, 60, 70, 80]
AtomicEnergy [10, 15, 20, 30, 50, 60, 70, 80]
AtomicAtomicAtomic [80, 70, 60, 50, 30, 20, 15, 10]
False 335
True ['ATOMIC', 'ENERGY', 'CENTRAL', 'SCHOOL']
14 Ex6:
-1 ('1', '2', '3', '4', '5', '6')
14 ('A', 't', 'o', 'm', 'i', 'c') A
True ('5', '+', '8')
True 13
True False
False True
True (10, 20, 10.0, 20.0) (10, 20, 10, 20)
central (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
CENTR (20, 30, 40) (30, 40) (20, 40, 60)
NTRAL (100, 80, 60, 40, 20)
CENTRAL (10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120)
C-E-N-T-R-A-L 12 120 10 4
central Ex7:
('ATOMIC ', 'ENERGY', ' CENTRAL SCHOOL') Enter no of terms of the Fibonacci Series10
('ATOMIC', ' ', 'ENERGY CENTRAL SCHOOL') 0 1 1 2 3 5 8 13 21 34
Ex3: Ex8:
Enter String :Atomic Energy Central School {'python': 500, 'C++': 400, 'Java': 450, 'Oracle': 800}
No of Upper Case characters 4 Length : 4
No of Lower Case characters 21 python Book costs Rs. 500
Ex4: C++ Book costs Rs. 400
[10, 20, 30, 40, 50] 40 20 Java Book costs Rs. 450
['A', 'T', 'O', 'M', 'I', 'C'] M O Oracle Book costs Rs. 800
[10, 20, [30, 40], 50] [30, 40] 10 ['python', 'C++', 'Java', 'Oracle']
False False [10, 20, [30, 40], 50, 60] (500, 400, 450, 800)
[10, 20, 30, 40, 50, 60] [20, 30, 40] [20, 30, 40] {'python': 500, 'C++': 400, 'Java': 550, 'Oracle': 800}
[60, 40, 20] {'python': 500, 'C++': 400, 'Java': 550, 'Oracle': 800,
['ten', 'twenty', 30, 40, 50, 60] 'HTML': 250}
['ten', '9', '8', '7'] {'python': 500, 'C++': 400, 'Java': 550, 'HTML': 250}
Ex5: {'python': 500, 'Java': 550, 'HTML': 250}
['1', '2', '3', '4', '5', '6'] Book Not found
['A', 't', 'o', 'm', 'i', 'c'] {
['5', '+', '8'] "python": 500,
13 "Java": 550,
(10, 20, 30, 40, 50) "HTML": 250
[10, 20, 30, 40, 50] }

S.K,Mukherjee 11
500 Ex12:
python 500 15 20
Java 550 15
HTML 250 Ex13:
{'python': 500, 'Java': 550, 'HTML': 250, Enter a no6
'FORTRAN': 300, 'COBOL': 275} 720
Ex9: 720
Enter no of students:2 Ex14:
Enter Rollno:101 1. Add
Enter Name :GARIMA 2. Subtract
Enter Mark :89 3. Multiply
Enter Rollno:102 4. Divide
Enter Name :MANI Enter a :1
Enter Mark :78 Enter b :56
{101: ['GARIMA', 89], 102: ['MANI', 78]} Enter Choice:3
Enter Student Rollno :102 56
['MANI', 78] Ex15:
Ex 10: [12, 45, 65, -89, -62, 52, 79]
7 Enter the element to be searched:52
False Element found at 6
True
0b111 0xf 0o10 [12, 45, 65, -89, -62, 52, 79]
7 Enter the element to be searched:888
True Not found
A 65 Ex16:
(3+0j) [-78, -44, -20, 3, 5, 12, 56, 91]
(2, 1) Enter the item to be searched56
14 Element is present at index 6
5
a=3 and b=4 [-78, -44, -20, 3, 5, 12, 56, 91]
3 Enter the item to be searched888
42 Element is not present in array
3.78 380.0 101 -46 2.0 Ex17:
{1, 2, 3} Enter no of elements:5
yh Original List
['h', 'n', 'o', 'p', 't', 'y'] [46, 40, 87, 33, 22]
14 Sorted List
Ex11: [22, 33, 40, 46, 87]
5 Ex18:
720 Enter no of elements:5
2.0 Original List [40, 41, 62, 43, 14]
10 Sorted List: [14, 40, 41, 43, 62]
12 Ex:19
3.1622776601683795 Enter radius :3.5
6.4031242374328485 Enter length :4
179.9087476710785 3.141592653589793 Enter breadth: 12
5.192925985263684 Area of the circle = 38.465
0.26506869999696603 3.2238332233222913 Area of the rectangle= 48
4
Ex:20
3
200
S.K,Mukherjee 12
8000 Want to add more record(y/n) :y
Ex:21 Enter student Roll No:102
Welcome to the world of computers Enter student Name :GARIMA
Lets learn the art of python programming Want to add more record(y/n) :n
Python with MYSQL helps you build you a [{'roll': '101', 'name': 'SKM'}, {'roll': '102', 'name':
successful career 'GARIMA'}]
Welcome Q30.
Welcome to the world of computers Enter student Name :GARIMA
Enter the mark:78
['Welcome to the world of computers\n', 'Lets Enter Date of Birth DDMMMYYYY09DEC2000
learn the art of python programming\n', 'Python Want to add more record(y/n) :y
with MYSQL helps you build you a successful Enter student Name :KAVYAN
career'] Enter the mark:89
Ex22: Enter Date of Birth DDMMMYYYY16JUN2004
Welcome to the world of computers Want to add more record(y/n) :n
Lets learn the art of python programming [{'name': 'GARIMA', 'mark': 78, 'age': {'day': '09',
Python with MYSQL helps you build you a 'month': 'DEC', 'year': '2000'}}, {'name': 'KAVYAN',
successful career 'mark': 89, 'age': {'day': '16', 'month': 'JUN', 'year':
'2004'}}]
Ex23: Ex31:
Welcome To The World Of Computers Lets Learn Enter student Name :SKM
The Art Of Python Programming Python With Enter the mark:87
Mysql Helps You Build You A Successful Career Enter Date of Birth DDMMMYYYY10JUN1989
Ex24: {'name': 'SKM', 'mark': 87, 'age': {'day': '10',
Welcome to the world of computers 'month': 'JUN', 'year': '1989'}}
Lets learn the art of python programming Want to add more record(y/n) :y
Python with MYSQL helps you build you a Enter student Name :GARIMA
successful career Total no of vowels:36 Enter the mark:78
Q25. Welcome to the world of computers Enter Date of Birth DDMMMYYYY16jun2002
Lets learn the art of python programming {'name': 'GARIMA', 'mark': 78, 'age': {'day': '16',
Python with MYSQL helps you build you a 'month': 'jun', 'year': '2002'}}
successful career Total no of Lower Case:102 Total Want to add more record(y/n) :n
no of Upper Case:8 Enter student Name :GARIMA
dict_values(['GARIMA', 78, {'day': '16', 'month':
Q26. Welcome to the world of computers!!!
'jun', 'year': '2002'}])
Lets learn the art of python 3.8 programming
Python with #MYSQL helps you build you a Ex32: No of Records: 3
successful career Total no of alphabets: 110 Total Ex33. Enter SN to be searched:2
no of digits :2 Total no of Spl Characters :28 Name : Tim Berners-Lee Subject : World Wide
Q27. Web
Enter the word to be searched :the Ex34:
2 1.PUSH
Welcome to the world of computers!!! 2.POP
Lets learn the art of python 3.8 programming 3.DISPLAY
Python with #MYSQL helps you build you a 4.EXIT
successful career Enter your choice1
Q28. [45, 27, 60, 16, 81, 41, 39, 16, 0, 40] Enter any number10
0 16 16 27 39 40 41 45 60 81
1.PUSH
Q29.
2.POP
Enter student Roll No:101
3.DISPLAY
Enter student Name :SKM
S.K,Mukherjee 13
4.EXIT >>>
Enter your choice1 Ex35:
Enter any number20
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice1
Enter your choice1 Enter any number10
Enter any number30
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice1
Enter your choice3 Enter any number20
['10', '20', '30']
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice1
Enter your choice2 Enter any number30
Deleted element 30
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice3
Enter your choice3 ['10', '20', '30']
['10', '20']
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice2
Enter your choice2 Deleted element 10
Deleted element 20
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice2
Enter your choice3 Deleted element 20
['10']
1.PUSH
1.PUSH 2.POP
2.POP 3.DISPLAY
3.DISPLAY 4.EXIT
4.EXIT Enter your choice3
Enter your choice4 ['30']
S.K,Mukherjee 14
Enter your choice4
1.PUSH Ex37:
2.POP
3.DISPLAY 1.Add Employee Data
4.EXIT 2.Delete Employee Data
Enter your choice4 3.View Employee Data
>>> 4.EXIT
Enter your choice1
Enter Employee No:101
Enter Employee Name:SKM
Ex36:
1.Add Employee Data 1.Add Employee Data
2.Delete Employee Data 2.Delete Employee Data
3.View Employee Data 3.View Employee Data
4.EXIT 4.EXIT
Enter your choice1 Enter your choice1
Enter Employee No:101 Enter Employee No:102
Enter Employee Name:PRATIK Enter Employee Name:GARIMA

1.Add Employee Data 1.Add Employee Data


2.Delete Employee Data 2.Delete Employee Data
3.View Employee Data 3.View Employee Data
4.EXIT 4.EXIT
Enter your choice1 Enter your choice3
Enter Employee No:102 {'101': 'SKM', '102': 'GARIMA'}
Enter Employee Name:GARIMA
1.Add Employee Data
1.Add Employee Data 2.Delete Employee Data
2.Delete Employee Data 3.View Employee Data
3.View Employee Data 4.EXIT
4.EXIT Enter your choice2
Enter your choice3
{'101': 'PRATIK', '102': 'GARIMA '} 1.Add Employee Data
2.Delete Employee Data
1.Add Employee Data 3.View Employee Data
2.Delete Employee Data 4.EXIT
3.View Employee Data Enter your choice3
4.EXIT {'102': 'GARIMA'}
Enter your choice2
1.Add Employee Data
1.Add Employee Data 2.Delete Employee Data
2.Delete Employee Data 3.View Employee Data
3.View Employee Data 4.EXIT
4.EXIT Enter your choice4
Enter your choice3 >>>
{'101': 'PRATIK'} Ex:38
Output is as same as output of Q37
1.Add Employee Data Ex39:
2.Delete Employee Data ('empcode', 'int(11)', 'NO', 'PRI', None, '')
3.View Employee Data ('empname', 'varchar(25)', 'YES', '', None, '')
4.EXIT
S.K,Mukherjee 15
('address', 'varchar(50)', 'YES', '', None, '') (523, 'KUMAR', 'KOLKATA', 'CSC', 'SCHOLAR',
('deptcode', 'varchar(3)', 'YES', '', None, '') 'M', None, None, 'JAD')
('designation', 'varchar(15)', 'YES', '', None, '') Ex40:
('gender', 'char(1)', 'YES', '', None, '') ('information_schema',)
('mobile', 'varchar(10)', 'YES', '', None, '') ('mysql',)
('basicsalary', 'decimal(10,2)', 'YES', '', None, '') ('rail',)
(123, 'SKM', 'UCIL COLONY', 'CSC', 'TEACHER', ('sample',)
'M', '9869071856', Decimal('75052.50')) ('school',)
(223, 'GARIMA', 'KOLKATA', 'BIO', 'STUDENT', ('sys',)
'M', '886907165819', Decimal('0.00')) ('SKM',)
(323, 'BABU', 'TATA NAGAR', 'ART', Ex41-47:
'STUDENT', 'F', None, Decimal('0.00')) ('rollno', 'int(11)', 'NO', 'PRI', None, '')
(423, 'ISHA', 'UCIL COLONY', 'COM', ('sname', 'varchar(25)', 'YES', '', None, '')
'TEACHER', 'M', '8764440747', Decimal('55000.00')) ('address', 'varchar(50)', 'YES', '', None, '')
(523, 'KUMAR', 'KOLKATA', 'CSC', 'SCHOLAR', ('deptcode', 'varchar(3)', 'YES', '', None, '')
'M', None, None) ('gender', 'char(1)', 'YES', '', None, '')
('empcode', 'int(11)', 'NO', 'PRI', None, '') ('mobile', 'varchar(10)', 'YES', '', None, '')
('empname', 'varchar(25)', 'YES', '', None, '') (1, 'SKM', 'UCIL COLONY', 'CSC', 'M',
('address', 'varchar(50)', 'YES', '', None, '') '9869071856')
('deptcode', 'varchar(3)', 'YES', '', None, '') (2, 'GARIMA', 'KOLKATA', 'BIO', 'M',
('designation', 'varchar(15)', 'YES', '', None, '') '886907165819')
('gender', 'char(1)', 'YES', '', None, '') (3, 'BABU', 'TATA NAGAR', 'ART', 'F', None)
('mobile', 'varchar(10)', 'YES', '', None, '') (4, 'ISHA', 'UCIL COLONY', 'COM', 'M',
('basicsalary', 'decimal(10,2)', 'YES', '', None, '') '8764440747')
('loc', 'varchar(3)', 'YES', '', None, '') (5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None)
(123, 'SKM', 'UCIL COLONY', 'CSC', 'TEACHER', ('rollno', 'int(11)', 'NO', 'PRI', None, '')
'M', '9869071856', Decimal('75052.50'), 'JAD') ('sname', 'varchar(25)', 'YES', '', None, '')
(223, 'GARIMA', 'KOLKATA', 'BIO', 'STUDENT', ('address', 'varchar(35)', 'YES', '', None, '')
'M', '886907165819', Decimal('0.00'), None) ('deptcode', 'varchar(3)', 'YES', '', None, '')
(323, 'BABU', 'TATA NAGAR', 'ART', ('gender', 'char(1)', 'YES', '', None, '')
'STUDENT', 'F', None, Decimal('0.00'), None) ('mobile', 'varchar(10)', 'YES', '', None, '')
(423, 'ISHA', 'UCIL COLONY', 'COM', ('mark', 'int(3)', 'YES', '', None, '')
'TEACHER', 'M', '8764440747', Decimal('55000.00'), ('age', 'int(2)', 'YES', '', None, '')
None) (1, 'SKM', 'UCIL COLONY', 'CSC', 'M',
(523, 'KUMAR', 'KOLKATA', 'CSC', 'SCHOLAR', '9869071856', None, None)
'M', None, None, 'JAD') (2, 'GARIMA', 'KOLKATA', 'BIO', 'M',
('CSC',) '886907165819', None, None)
('COM',) (3, 'BABU', 'TATA NAGAR', 'ART', 'F', None,
('BIO',) None, None)
('ART',) (4, 'ISHA', 'UCIL COLONY', 'COM', 'M',
(1, 'ART') '8764440747', None, None)
(1, 'BIO') (5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None,
(1, 'COM') None, None)
(2, 'CSC') (1, 'SKM', 'UCIL COLONY', 'CSC', 'M',
(123, 'SKM', 'UCIL COLONY', 'CSC', 'TEACHER', '9869071856', None, None)
'M', '9869071856', Decimal('75052.50'), 'JAD') (2, 'GARIMA', 'KOLKATA', 'BIO', 'M',
(223, 'GARIMA', 'KOLKATA', 'BIO', 'STUDENT', '886907165819', None, None)
'M', '886907165819', Decimal('0.00'), None) (4, 'ISHA', 'UCIL COLONY', 'COM', 'M',
(323, 'BABU', 'TATA NAGAR', 'ART', '8764440747', None, None)
'STUDENT', 'F', None, Decimal('0.00'), None) (5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None,
None, None)
S.K,Mukherjee 16
(1, 'SKM', 'UCIL COLONY', 'CSC', 'M', lc+=1
'9869071856', None, 18) if i.isupper():
(2, 'GARIMA', 'KOLKATA', 'BIO', 'M', uc+=1
'886907165819', None, 18) if i.isspace():
(4, 'ISHA', 'UCIL COLONY', 'COM', 'M', s+=1
'8764440747', None, 18) print(data)
(5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None, print('No of Vowels',v)
None, 18) print('No of Consonants',len(data)-v-s)
>>> print('Upper Case Characters',uc)
Ex48. print('Lower Case Characters',lc)
(1, 'SKM', 'UCIL COLONY', 'CSC', 'M', 3.
'9869071856', None, 18) import pickle
(2, 'GARIMA', 'KOLKATA', 'BIO', 'M', with open('sample.dat','wb') as f:
'886907165819', None, 18) n=int(input('Enter no of students:'))
(4, 'ISHA', 'UCIL COLONY', 'COM', 'M', l=[]
'8764440747', None, 18) for i in range(n):
(5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None, rno=input('Enter Roll no:')
None, 18) l.append(rno)
Enter student name:GARIMA name=input('Enter name:')
(1, 'SKM', 'UCIL COLONY', 'CSC', 'M', l.append(name)
'9869071856', None, 18) pickle.dump(l,f)
(4, 'ISHA', 'UCIL COLONY', 'COM', 'M',
'8764440747', None, 18) with open('sample.dat','rb') as f:
(5, 'KUMAR', 'KOLKATA', 'CSC', 'M', None, n=input('Enter RollNo to be searched')
None, 18) d=pickle.load(f)
1. for i in range(0,len(d),2):
with open('sample.txt','w') as f: if n==d[i]:
f.write('''Welcome to the world of print(d[i+1])
computers 4.
Lets learn the art of python programming
Python with MYSQL helps you build you a
successful career''')

with open('sample.txt','r') as f:
for i in f.readlines():
l=i.split()
for i in l:
print(i,end='#')
2.
with open('sample.txt','w') as f:
f.write("Welcome to the world of
computers")

with open('sample.txt','r') as f:
data=f.read()
v=lc=uc=s=0
for i in data:
if i in 'aeiouAEIOU':
v+=1
if i.islower():

S.K,Mukherjee 17

You might also like