Practical FileXII
Practical FileXII
SCHOOL
UDHAM SINGH NAGAR
Computer Science (083)
Practical File(2024-25)
To:
Name: Mrs.
RoomaJoshi
Class:
Section (PGT
COMP.SC)
7. Program to find the minimum value in the list and its index number.
10. Program to write roll no, name and marks of the students in a data file Marks.dat.
11. Program to display rollno , name and marks of the students in a data file Marks.dat.
12. Program to write data , read and display in and from text file ‘test3.txt’.
13. Program to read and display those lines from file that start with alphabet ‘W’.
14. Program to read and display those lines from file that end with alphabet ‘g’.
15. Program to write data , read and display in and from a csv file ‘student.csv’.
Python Programs
1 . Menu based program to find sum, subtraction, multiplication and division of values.
sum=0
for num in range(21):
if num%2==0:
sum=sum+num
print("Sum of even values=",sum)
for i in range(1,6):
print()
for j in range(1,i+1):
print ('*',end="")
import random
AR="HELLO WORLD";
FROM=random.randint(1,3)
for K in range(0, FROM):
print (AR[K],end="#")
7. Program to find the minimum value in the list and its index number :
L=eval(input('Enter list values'))
length=len(L) #length=6
min=L[0] #min=10
loc=0
for i in range(length): #0,1,2,3,4,5
if L[i]<min:
min=L[i] #min=1
loc=i
print("Minimum value=",min)
print("Location=",loc)
def largest():
a=int(input("Enter first number="))
b=int(input("Enter second number="))
if a>b :
print ("Largest value= ", a)
else:
print ("Largest value=" , b)
return
largest()
defchangeme( mylist ):
print ("inside the function before change ", mylist)
mylist[0]=1000
print ("inside the function after change ", mylist)
return
list1 = [10,20,30]
print ("outside function before calling function", list1)
changeme( list1 )
print ("outside function after calling function", list1)
10. Program to write rollno , name and marks of the students in a datafile Marks.dat.:
fileinp=open("Marks.dat","r")
whilestr:
str=fileinp.readline()
print(str)
fileinp.close()
12. Program to write data , read and display in and from text file ‘test3.txt’.
fh=open("test3.txt","w")
fh.write("We are writing \n")
fh.write("data \n")
fh.write("to a text file \n")
print("Data Written\n \n")
fh.close()
fh=open("test3.txt","r")
lines=fh.readlines()
print("Reading and displaying from text fom file\n")
for line in lines:
print(line,end='')
fh.close()
13. Program to read and display those lines from file that start with alphabet ‘W’.
file1=open("test3.txt","r")
count=0
str1=file1.readlines()
print(str1)
for i in str1:
if i[0]=='W':
print (i)
file1.close()
14. Program to read and display those lines from file that end with alphabet ‘g’.
file1=open("test3.txt","r")
count=0
str1=file1.readlines()
for i in str1:
if i[-3]=='g':
count+=1
print("Number of lines which end with 'g'=",count)
file1.close()
15. Program to write data , read and display in and from a csv file ‘student.csv’.
import csv
fh=open("student.csv","w")
stuwriter=csv.writer(fh)
stuwriter.writerow([1,'aman',50])
stuwriter.writerow([2,'Raman',60])
print("Data Entered\n \n")
fh.close()
import csv
fh=open("student.csv","r")
stureader=csv.reader(fh)
print("Data Displayed:")
for rec in stureader:
print(rec)
fh.close()