Computer Science of Vaibhav Sengar
Computer Science of Vaibhav Sengar
PYTHON
Neetu Chauhan
(CLASS 11TH (B)
ACKNOWLEDGEMENT
Neetu Chauhan
(Class 11th)
Certificate
PRINCIPAL
______________________
INDEX
PRACTICAL FILE - COMPUTER SCIENCE (083)
LIST OF PRACTICALS (2024-25)
Programming Language: Python
def nthfiboterm(n):
if n<=1:
return n
else:
return (nthfiboterm(n-1)+nthfiboterm(n-2))
f = open("file1.txt")
for line in f:
words = line.split()
for w in words:
print(w+'#',end='')
print()
f.close()
India is my country
I love python
Python learning is fun
OUTPUT:
India#is#my#country#
I#love#python#
Python#learning#is#fun#
Program 7 : Program to read the content of file and
display the total number of consonants, uppercase,
vowels and lower case characters‟
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close() f=open('student.dat','rb')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
OUTPUT:
Enter Roll Number :1
Enter Name :Amit
Add More ?(Y)y
Enter Roll Number :2
Enter Name :Jasbir
Add More ?(Y)y
Enter Roll Number :3
Enter Name :Vikral
Add More ?(Y)n
Enter Roll number to search :2
## Name is : Jasbir ##
Search more ?(Y) :y
Enter Roll number to search :1
## Name is : Amit ##
Search more ?(Y) :y
Enter Roll number to search :4
####Sorry! Roll number not found ####
Search more ?(Y) :n
Program 9 : Program to create binary file to
store Rollno,Name and Marks and update
marks of entered Rollno
f1 = open("file2.txt")
f2 = open("file2copy.txt","w")
for line in f1:
if 'a' not in line:
f2.write(line)
print(“## File Copied Successfully! ##”)
f1.close()
f2.close()
NOTE: Content of file2.txt
a quick brown fox
one two three four
five six seven
India is my country
eight nine ten
bye!
OUTPUT:
import math