Code – Aditya Anoop
Consider a binary file “student.dat” that stores information about students using a
dictionary write a python function countrec() to display the number of students who get
minimum 75 percentage.
For example :
If the information stored is
{Admnno : 2003 , name : ‘Ankit’ , percentage : 90}
{Admnno : 2002 , name : ‘Binay’ , percentage : 70}
{Admnno : 2000 , name : ‘saroj’ , percentage : 80}
Then the output :
No of students who got minimum 75 percent = 2
Code:
import pickle
def countrec():
c=0
F=open(“student.dat”,”rb”)
try:
while True:
d=pickle.load(f)
If d[“percentage”]>=75:
c=c+1
except EOFError:
f.close()
print(“no of students who got minimum 75 pecentage=”,c)
countrec()
Code – Himshreya Mondal
A csv file containing the details of employees using the structure of a list as
[“eno”,”name”,”salary”] . Find and display the number of employees getting salary more
than 50000 from the file emp.csv
For example:
If the information stored is
[1001,”Ankit”,70000]
[2002,”Binay”,40000]
[3200,”Saroj”,35000]
Then the output :
No of employees having salary > 50000 = 1
Code:
import csv:
f=open(“emp.csv”,”r”,newline=’’)
freader=csv.reader(f)
c=0
for I in freader:
if i[2]>50000:
c=c+1
Print(“No of employees having salary > 50000 =”,c)
Code – Preyashi Chakraborty
Consider a text file called alphabet.txt and then write a method countvoco() to read the
textfile and count the no of words starting with a vowel and an consonant in the text file
alphabet.txt
For example:
If the information stored is
The greatest glory in living lies not in never falling but in rising every time we fall
Then the output
No of words starting with vowel = 4
No of words starting with consonants = 13
Code :
def countvoco():
f=open(“alphabet.txt”,”r”)
s=f.read()
l=s.split()
a=0
b=0
v=”AEIOUaeiou”
For i in l:
if i[0] in v:
a=a+1
else:
b=b+1
print(“No of words starting with vowel =”,a)
print(“No of words starting with consonants =”,b)
countvoco()
f.close()