Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Ramanlal Shorawala International School

COMPUTER SCIENCE (O83)


PRACTICAL FILE

PYTHON PROGRAMS

Academic Year : 2021-22

submitted to : submitted by :

Mr.Neetesh Dixit Arish kumar

class : 12 ‘ c’
Index
S.no Date CONTENTS Page no. TEACHER'S
INITIAL
1 1/11/22 Acknowledgement 1
2 1/11/22 Declaration 2
3 1/11/22 Certification 3
4 1/11/22 Python program1 4
5 1/11/22 Python program 2 5
6 1/11/22 Python program 3 6 to 7
7 1/11/22 Python program 4 8 to 9

9 2/11/22 Python program6 11 to 12


10 2/11/22 Python program7 13
11 2/11/22 Python program8 14
12 2/11/22 Python program9 15
13 2/11/22 Python program10 16
14 2/11/22 Python program11 17
15 2/11/22 Python program12 18
16 2/11/22 Python program13 19

18 2/11/22 Python program15 21


19 3/11/22 Python program16 22 to 23
20 3/11/22 Python program17 24
21 3/11/22 Python program18 25
22 3/11/22 Python program19 26
23 3/11/22 Python program20 27
24 4/11/22 My sql 1 28 to 30
25 4/11/22 MY sql 2 31 to 32

26 4/11/22 My sql 3 33 to 36
27 4/11/22 My sql 4 37 to 38
28 4/11/22 Mt sql 5 39
Acknowledgement

I am really really grateful to my Computer Teacher Mr.


Neetesh Dixit Sir for advising me and introducing the
project to me in a easy to understand way which has
helped me complete my project easily and effectively on
time.
I am dearly obliged to (Mr.Neetesh Dixit) for giving me
an opportunity to work on these practical which has
provided valuable information about ( python
programs).
Thank you.

Student’s Name: Arish kumar

Teacher Signature Class: 12 ’c ‘

Roll No.: 01

Subject: Computer science


DECLARATION

Respected Sir, I Arish kumar a student of 12 ’c’ do


hereby solemnly affirm and declare as under:That python
program is done by me in guidance of Mr.Neetesh Dixit
. That I have created the project as per the school rules
and regulation .

Student’s Name: Arish kumar

C lass: 12’c’

Teacher Signature Roll No.: 01

Subject: Computer science


Certificate

This is to certify that the content of these


prectical“python program” by “Arish kumar ” is the
bonafide work of him/her submitted to “Ramanlal
Shorawala International School”, for consideration in
the partial accomplishment of the provision of CBSE,
New Delhi for the award of Senior School Certificate
in Computer.

The original research work was carried out by him


under my supervision in the academic year 2021-
2022. On the basis of the declaration made by him, I
recommend the project report for evaluation.

Internal Examiner External Examiner


1.Python program that print if the integer
is a1/2/3 digit number
num=int(input("Enter a number : "))

if num<0:

print("Invalid entry")

elif num<10:

print("single digit number")

elif num<100:

print("double digit number")

elif num<1000:

print("Three digit number")

else:

print("not vailed number, The number should lie between 0 to 999 only")

output of the program


2 .python program that multiplies two
number without using the*oprator.
n1=int(input("enter frist number:"))

n2=int(input("enter second number:"))

product=0

count=n1

while count>0:

count=count-1

product=product+n2

print("the product of ",n1,"and",n2,"is",product)

output of the program


3. Python program to implement stack
operation
class Stack:

def __init__(self):

self.items = []

def is_empty(self):

return self.items == []

def push(self, data):

self.items.append(data)

def pop(self):

return self.items.pop()

s = Stack()

while True:

print('push <value>')

print('pop')

print('quit')

do = input('What would you like to do? ').split()

operation = do[0].strip().lower()

if operation == 'push':

s.push(int(do[1]))
elif operation == 'pop':

if s.is_empty():

print('Stack is empty.')

else:

print('Popped value: ', s.pop())

elif operation == 'quit':

break

output of the program


4.python program that read a line and
print its statistics
line=input("enter a line:")
lowercount=uppercount=0
digitcount=alphacount=0
for a in line:
if a.islower():
lowercount+=1
elif a.isupper():
uppercount+=1
elif a.isdigit():
digitcount+=1
if a.isalpha():
alphacount+=1
print("number of uppercase letters:",uppercount)
print("number of lowercase letters:",lowercount)
print("number of alphabets:",alphacount)
print("number of digit:",digitcount)
output of the program
5. write a program that adds individual
elements of list 2 and 3 to list1.
list1=['a','b','c']

list2=['h','i','t']

list3=['o','i','2']

print("originally :")

print("list1=",list1)

print("list2=",list2)

print("list3=",list3)

list3.extend(list1)

list3.extend(list2)

print("after adding elements of two list indiviually ,list now is :")

print(list3)

output of the program


6.program to implement queue operation
class Queue:

def __init__(self):

self.items = []

def is_empty(self):

return self.items == []

def enqueue(self, data):

self.items.append(data)

def dequeue(self):

return self.items.pop(0)

q = Queue()

while True:

print('enqueue <value>')

print('dequeue')

print('quit')

do = input('What would you like to do? ').split()

operation = do[0].strip().lower()

if operation == 'enqueue':

q.enqueue(int(do[1]))

elif operation == 'dequeue':

if q.is_empty():

print('Queue is empty.')
else:

print('Dequeued value: ', q.dequeue())

elif operation == 'quit':

break

output of the program


7.write a program r that input a main
steing and then crates an ancrypet
def arCalc(x,y):

return x+y,x-y,x*y,x/y,x%y

#_main_

num1=int(input("enter number1:"))

num2=int(input("enter number2:"))

add,sub,mult,div,mod=arCalc(num1,num2)

print("sum of given number:",add)

print("subtraction of given number:",sub)

print("product of given number:",mult)

print("modulo of given number:",mod)

output of the program


8.python program that take string and
encrypt it
def encrypt(sttr,enkey):

return enkey.join(sttr)

def decrypt(sttr,enkey):

return sttr.split(enkey)

#_main_

mainstring=input("enter main string:")

encryptstr=input("enter encrytion key:")

enstr=encrypt(mainstring,encryptstr)

delst=decrypt(enstr,encryptstr)

destr="".join(delst)

print("the encrypted string is",enstr)

print("string after decryption is:",destr)

output of the program


9.python program that make file.
count=int(input("how many student are there in the class?"))

fileout=open("marks.txt","w")

for i in range(count):

print("enter details for student",(i+1),"below:")

rollno=int(input("Rollno:"))

name=input("name:")

marks=float(input("marks:"))

rec=str(rollno)+","+name+","+str(marks)+'\n'

fileout.write(rec)

fileout.close()

output of the program


10.python program that make binary file.
import pickle

stu={}

stufile=open('stu.dat','wb')

ans='y'

while ans=='y':

rno=int(input("enter roll number:"))

name=input("enter name:")

marks=float(input("enter marks:"))

stu['Rollno']=rno

stu['Name']=name

stu['Marks']=marks

pickle.dump(stu,stufile)

ans=input("want to enter more records?(y/n)...")

stufile.close()

output of the program


11.traversing a linear list
def traverse(AR):

size=len(AR)

for i in range(size):

print(AR[i], end='')

#_main_

size=int(input("enter the size of linear to be input:"))

AR=[None]*size

print("enter elements for the linear lisrt")

for i in range(size):

AR[i]=int(input("element"+str(i)+":"))

print("traversing the list:")

traverse(AR)

output of the program


12.deletion of an element from a sorted
lx=[1,2,3,56,3,3,22]

x.sort()

del(x[1:3])

print("List after deleting group of elements:",x)

a=22

for i in range(len(x)):

if(x[i]<a):

pass

elif(x[i]==a):

pass

elif(x[i]>a):

x[i-1]=x[i]

x.pop()

print("After deleting a element :",x)

x.clear()

print("After clear function:",x)inear list

output of the program


13. python program to find prime number or
not.
n=int(input("Enter the number"))

c=1

for i in range(2,n):

if n%i==0:

c=0

if c==1:

print("Number is prime")

else:

print("Number is not prime")

output of the program


14.python program that output fibonacci
series
n=int(input("Enter the number of terms in fibonacci series"))

a,b=0,1

s=a+b

print(a,b,end=" ")

for i in range(n-2):

print(a+b,end=" ")

a,b=b,a+b

s=s+b

print()

print("Sum of",n,"terms of series =",s)

output of the program


15.pyhton program to find vowels in string.
st=input("Enter the string")

print("Entered string =",st)

st=st.lower()

c=0

v=['a','e','i','o','u']

for i in st:

if i in v:

c+=1

print("Number of vowels in entered string =",c)

output of the program


16.pyhton program for number in
asscending order
x=int(input("enter frist number"))

y=int(input("enter second number"))

z=int(input("enter third number"))

if x<y and x<z:

if y<z:

f,s,t=x,y,z

else:

f,s,t=x,y,z

elif y<x and y<z:

if x<z:

f,s,t=y,x,z

else:

f,s,t=y,z,x

else:

if x<y:

f,s,t=z,x,y

else:

f,s,t=z,y,x

print("number in asscending order are",f,s,t)


ouitput of the program
17.python program to sum of integers
def findSum(lst,num):

if num==0:

return 0

else:

return lst[num-1]+findSum(lst,num-1)

mylist = []

num = int(input("Enter how many number :"))

for i in range(num):

n = int(input("Enter Element "+str(i+1)+":"))

mylist.append(n)

sum = findSum(mylist,len(mylist))

print("Sum of List items ",mylist, " is :",sum)

output of the program


18. Program to find the occurence of any
word in a string
def countWord(str1,word):

s = str1.split()

count=0

for w in s:

if w==word:

count+=1

return count

str1 = input("Enter any sentence :")

word = input("Enter word to search in sentence :")

count = countWord(str1,word)

if count==0:

print("## Sorry! ",word," not present ")

else:

print("## ",word," occurs ",count," times ## ")

output of the program


19. WAP to input a year and check whether
the year is leap year or not
y=int(input("Enter the year: "))

if y%400==0:

print("The year is a Century Leap Year")

elif y%100!=0 and y%4==0:

print("Year is a Leap year")

else:

print("Year is not a leap year")

output of the program


20.python program to find greater number
a=float(input("Enter the first number: "))

b=float(input("Enter the second number: "))

c=float(input("Enter the third number: "))

if a>=b:

if a>=b:

print("First number :",a,"is greatest")

if b>a:

if b>c:

print("Second number :",b,"is greatest")

if c>a:

if c>b:

print("Third number :",c,"is greatest")

output of the program


21.Program to connect with database and store
record of employeeand display records
import mysql.connector as mycon

con = mycon.connect(host='127.0.0.1',user='root',password="admin")

cur = con.cursor()

cur.execute("create database if not exists company")

cur.execute("use company")

cur.execute("create table if not exists employee(empno int, name varchar(20), dept

varchar(20),salary int)")

con.commit()

choice=None

while choice!=0:

print("1. ADD RECORD ")

print("2. DISPLAY RECORD ")

print("0. EXIT")

choice = int(input("Enter Choice :"))

if choice == 1:

e = int(input("Enter Employee Number :"))

n = input("Enter Name :")

d = input("Enter Department :")

s = int(input("Enter Salary :"))

query="insert into employee values({},'{}','{}',{})".format(e,n,d,s)


cur.execute(query)

con.commit()

print("## Data Saved ##")

elif choice == 2:

query="select * from employee"

cur.execute(query)

result = cur.fetchall()

print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT",

"%10s"%"SALARY")

for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])

elif choice==0:

con.close()

print("## Bye!! ##")

else:

print("## INVALID CHOICE ##")

output of the program


1. ADD RECORD

2. DISPLAY RECORD

0. EXIT

Enter Choice :1

Enter Employee Number :1


Enter Name :AMIT

Enter Department :SALES

Enter Salary :9000

## Data Saved ##

1. ADD RECORD

2. DISPLAY RECORD

0. EXIT

Enter Choice :1

Enter Employee Number :2

Enter Name :NITIN

Enter Department :IT

Enter Salary :80000

## Data Saved ##

1. ADD RECORD

2. DISPLAY RECORD

0. EXIT

Enter Choice :2

EMPNO NAME DEPARTMENT SALARY

1 AMIT SALES 9000

2 NITIN IT 80000

1. ADD RECORD

2. DISPLAY RECORD

0. EXIT
22. Program to connect with database and table employee and display
record, if empno not found display appropriate message search employee
number in
import mysql.connector as mycon

con = mycon.connect(host='127.0.0.1',user='root',password="admin",

database="company")

cur = con.cursor()

print("#"*40)

print("EMPLOYEE SEARCHING FORM")

print("#"*40)

print("\n\n")

ans='y'

while ans.lower()=='y':

eno = int(input("ENTER EMPNO TO SEARCH :"))

query="select * from employee where empno={}".format(eno)

cur.execute(query)

result = cur.fetchall()

if cur.rowcount==0:

print("Sorry! Empno not found ")

else:

print("%10s"%"EMPNO", "%20s"%"NAME","%15s"%"DEPARTMENT",

"%10s"%"SALARY")

for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])

ans=input("SEARCH MORE (Y) :")


output of the program
########################################

EMPLOYEE SEARCHING FORM

########################################

ENTER EMPNO TO SEARCH :1

EMPNO NAME DEPARTMENT SALARY

1 AMIT SALES 9000

SEARCH MORE (Y) :y

ENTER EMPNO TO SEARCH :2

EMPNO NAME DEPARTMENT SALARY

2 NITIN IT 80000

SEARCH MORE (Y) :y

ENTER EMPNO TO SEARCH :4

Sorry! Empno not found

SEARCH MORE (Y) :n


23. Program to connect with database and update the
employee record of entered empno
import mysql.connector as mycon

con = mycon.connect(host='127.0.0.1',user='root',password="admin",

database="company")

cur = con.cursor()

print("#"*40)

print("EMPLOYEE UPDATION FORM")

print("#"*40)

print("\n\n")

ans='y'

while ans.lower()=='y':

eno = int(input("ENTER EMPNO TO UPDATE :"))

query="select * from employee where empno={}".format(eno)

cur.execute(query)

result = cur.fetchall()

if cur.rowcount==0:

print("Sorry! Empno not found ")

else:

print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT",

"%10s"%"SALARY")

for row in result:


print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])

choice=input("\n## ARE YOUR SURE TO UPDATE ? (Y) :")

if choice.lower()=='y':

print("== YOU CAN UPDATE ONLY DEPT AND SALARY ==")

print("== FOR EMPNO AND NAME CONTACT ADMIN ==")

d = input("ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT

TO CHANGE )")

if d=="":

d=row[2]

try:

s = int(input("ENTER NEW SALARY,(LEAVE BLANK IF NOT

WANT TO CHANGE ) "))

except:

s=row[3]

query="update employee set dept='{}',salary={} where empno={}".format

(d,s,eno)

cur.execute(query)

con.commit()

print("## RECORD UPDATED ## ")

ans=input("UPDATE MORE (Y) :")

output of the program


########################################
EMPLOYEE UPDATION FORM
########################################
ENTER EMPNO TO UPDATE :2
EMPNO NAME DEPARTMENT SALARY
2 NITIN IT 90000
## ARE YOUR SURE TO UPDATE ? (Y) :y
== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO
CHANGE )
ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE )
## RECORD UPDATED ##
UPDATE MORE (Y) :y
ENTER EMPNO TO UPDATE :2
EMPNO NAME DEPARTMENT SALARY
2 NITIN IT 90000
## ARE YOUR SURE TO UPDATE ? (Y) :y
== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO
CHANGE )SALES
ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE )
## RECORD UPDATED ##
UPDATE MORE (Y) :Y
ENTER EMPNO TO UPDATE :2
EMPNO NAME DEPARTMENT SALARY
2 NITIN SALES 90000
## ARE YOUR SURE TO UPDATE ? (Y) :Y
== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO
CHANGE )
ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE )
91000
## RECORD UPDATED ##
UPDATE MORE (Y) :Y
ENTER EMPNO TO UPDATE :2
EMPNO NAME DEPARTMENT SALARY
2 NITIN SALES 91000
## ARE YOUR SURE TO UPDATE ? (Y) :N
UPDATE MORE (Y) :N
24. Program to connect with database and delete the record of
entered employee number.
import mysql.connector as mycon

con = mycon.connect(host='127.0.0.1',user='root',password="admin",

database="company")

cur = con.cursor()

print("#"*40)

print("EMPLOYEE DELETION FORM")

print("#"*40)

print("\n\n")

ans='y'

while ans.lower()=='y':

eno = int(input("ENTER EMPNO TO DELETE :"))

query="select * from employee where empno={}".format(eno)

cur.execute(query)

result = cur.fetchall()

if cur.rowcount==0:

print("Sorry! Empno not found ")

else:

print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT",

"%10s"%"SALARY")

for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])

choice=input("\n## ARE YOUR SURE TO DELETE ? (Y) :")

if choice.lower()=='y':

query="delete from employee where empno={}".format(eno)


cur.execute(query)

con.commit()

print("=== RECORD DELETED SUCCESSFULLY! ===")

ans=input("DELETE MORE ? (Y) :")

output of the program


########################################

EMPLOYEE DELETION FORM

########################################

ENTER EMPNO TO DELETE :2

EMPNO NAME DEPARTMENT SALARY

2 NITIN SALES 91000

## ARE YOUR SURE TO DELETE ? (Y) :y

=== RECORD DELETED SUCCESSFULLY! ===

DELETE MORE ? (Y) :y

ENTER EMPNO TO DELETE :2

Sorry! Empno not found


25. SELECT jobtitle,salary FROM job;

You might also like