CS Practical Programs
CS Practical Programs
PROGRAMS
PYTHON REVISION 1 & 2
1.To write a menu driven Python Program to perform
Arithmetic
operations (+, -, *, /).
while True:
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
ch=int(input("Enter your choice:"))
a=int(input("Enter the First Number:"))
b=int(input("Enter the Second Number:"))
if ch==1:
print("The Addition value is:",a+b)
elif ch==2:
print("The Subtraction value is:",a-b)
elif ch==3:
print("The Multiplication value is:",a*b)
elif ch==4:
print("The Division value is:",a/b)
else:
print("Invalid option")
break
2.To write a Python Program to display the
multiplication table of thegiven number.
num = int(input("Display multiplication table of:"))
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
3 To write a python program to pass list to a
function and double
the odd values and half even values of a list
and display list element
after changing.
def test(x):
new=[]
for i in x:
if i%2==0:
new.append(i//2)
else:
new.append(i*2)
return new
org=eval(input("enter the list u want to process"))
print("the original list is",org)
new=test(org)
print("the new list is",new)
4.ODD AND EVEN NUMBERS COUNT IN TUPLE.
def CountOfEO(t):
EC = OC = 0
for i in t:
if(i % 2 == 0):
EC = EC + 1
else:
OC = OC + 1
return EC,OC
t=eval(input("Enter the tuple"))
print("Tuple Items are = ", t)
eCount, oCount = CountOfEO(t)
print("The Count of Even Numbers in t = ", eCount)
print("The Count of Odd Numbers in t = ", oCount)
5.VOWELS COUNTING
import pickle
f=open("C:\\Users\\ADMIN\\Desktop\\rin.dat","rb")
search=int(input("enter your number to search"))
data=pickle.load(f)
for i in data:
if i==search:
print(stud[i])
f.close()
import pickle
f=open("C:\\Users\\ADMIN\\Desktop\\rin.dat","wb")
stud={}
n=int(input("enter the number of students"))
for i in range(n):
rollno=int(input("enter your number"))
name=str(input("enter your name"))
marks=str(input("enter your marks"))
stud[rollno]={}
stud[rollno]["name"]=name
stud[rollno]["marks"]=marks
print(stud)
pickle.dump(stud,f)
f.close()
import pickle
f=open("C:\\Users\\ADMIN\\Desktop\\rin.dat","rb+")
search=int(input("enter your number to update"))
newmark=int(input("enter your updated marks"))
data=pickle.load(f)
for i in data:
if i==search:
stud[rollno]["marks"]=newmark
print(stud)
f.close()
import csv
f = open("C:\\Users\\ADMIN\\Desktop\\rin.csv","w", newline="")
writer = csv.writer(f)
heading=["EmpNo", "Name", "Marks"]
writer.writerow(heading)
n = int(input("Enter the number of students: "))
for i in range(n):
empno = int(input("Enter your number: "))
name = input("Enter your name: ")
marks = input("Enter your marks: ")
data=[empno, name, marks]
writer.writerow(data)
f.close()
import csv
f = open("C:\\Users\\ADMIN\\Desktop\\stud.csv","w", newline="")
writer = csv.writer(f)
n = int(input("Enter the number of students: "))
for i in range(n):
rollno = int(input("Enter your stud number: "))
name = input("Enter your stud name: ")
marks = int(input("Enter your stuf marks "))
data=[rollno, name, marks]
writer.writerow(data)
f.close()
f = open("C:\\Users\\ADMIN\\Desktop\\stud.csv","r", newline="")
csvreader = csv.reader(f)
n = int(input("Enter the emo num to search "))
for i in csvreader:
print("student number",i[0])
print("student name", i[1])
print("student marks",i[2])
f.close()
import csv
f = open("C:\\Users\\ADMIN\\Desktop\\rin.csv","w", newline="")
writer = csv.writer(f)
heading=["userid", "pwd"]
writer.writerow(heading)
while True:
choice= str(input("do u want to continue"))
if choice=="y":
uname = str(input("Enter your uname "))
pwd= input("Enter your pws ")
data=[uname,pwd]
writer.writerow(data)
else:
break
f.close()
f = open("C:\\Users\\ADMIN\\Desktop\\rin.csv","r", newline="")
reader = csv.reader(f)
uname=str(input("enter the username u want to search for "))
for i in reader:
if i[0]==uname:
print("hello your password is",i[1])
f.close()