CS Practicals Exp 1,6,9,11,14
CS Practicals Exp 1,6,9,11,14
01 :
SOURCE CODE
sum = a + b
difference = a - b
product = a * b
quotient = a / b
remainder = a % b
print("WELCOME TO CALCULATOR")
while True:
print("5. Exit")
if choice == 1:
addition(a,b)
elif choice == 2:
subtraction(a,b)
elif choice == 3:
multiplication(a,b)
elif choice == 4:
divide(a,b)
elif choice == 5:
break
else:
OUTPUT
5. Exit
2+2=4
5. Exit
4-2=2
5. Exit
3*3=9
5. Exit
Quotient of 20 / 5 = 4.0
Remainder of 20 % 5 = 0
WELCOME TO CALCULATOR
5. Exit
Exp.no.06 :
SOURCE CODE
def showlines():
with open("story.txt",'r') as F:
s=F.read()
for w in s:
print(w)
elif w=='\n':
print(end=" ")
else:
print(w,end=" ")
showlines()
OUTPUT:
S o , w h a t e l s e d i d o u r p a r e n t s t e l l ?
Exp.no.09 :
SOURCE CODE
importpickle
def Create():
F=open("Students.dat",'ab') opt='y'
whileopt=='y':
Roll_No=int(input("Enterrollnumber:")) Name=input("Enter name:")
L=[Roll_No,Name] pickle.dump(L,F)
opt=input("doyouwanttoaddanotherstudentdetails(y/n):") F.close()
def search():
F=open("Students.dat",'rb')
no=int(input("enterRoll.Notosearch:")) found=0
try:
whileTrue:
S=pickle.load(F) if S[0]==no:
print("ThesearchedROll.Noisfoundanddetailsare:",S) found=1
break
except:
F.close()
if found==0:
print("ThesearchedRoll.Noisnotfound")
#MAINPROGRAM
Create()
search()
OUTPUT:
Enter rollnumber:1
Enter name:abc
Exp.no.11 :
SOURCE CODE
import csv
def Create():
F=open("Emp.csv",'w',newline='\n')
w=csv.writer(F)
opt='y'
while opt=='y':
L=[No,Name,sal]
w.writerow(L)
F.close()
def Search():
F=open("Emp.csv",'r',newline='\r\n')
found=0
row=csv.reader(F)
if data[0]==str(no):
print("====================")
print("Name:",data[1])
print("salary:",data[2])
print("====================")
found=1
break
if found==0:
print("not found")
F.close()
Create()
Search()
OUTPUT:
not found
Enter Employee Number:1
====================
Name: nandha
salary: 15000.0
====================
Exp.no.14 :
SOURCE CODE
def push(Arr,item) :
if item%5 == 0 :
Arr.append(item)
def pop(Arr):
if Arr==[] :
print("No item found")
else :
print("The deleted element :")
return Arr.pop()
def show():
if Arr==[] :
print("No item found")
else :
top = len(Arr)- 1
print("The stack elements are :")
for i in range(top,-1,-1) :
print(Arr[i] )
#Main program
Arr = []
top = None
while True :
print("*****STACK IMPLEMENTATION USING LIST*****")
print("1: PUSH")
print("2: Pop")
print("3: Show")
print("4: Exit")
ch = int(input("Enter ur choice :"))
if ch==1:
val=int(input("enter no to push :"))
push(Arr,val)
elif ch==2:
res = pop(Arr)
print(res)
elif ch==3:
show()
elif ch==0:
print("Bye")
break
OUTPUT :