0% found this document useful (0 votes)
33 views3 pages

File Handling Practical Code

Uploaded by

adityaanoop3771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

File Handling Practical Code

Uploaded by

adityaanoop3771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Code – Aditya Anoop

Consider a binary file “[Link]” 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(“[Link]”,”rb”)

try:

while True:

d=[Link](f)

If d[“percentage”]>=75:

c=c+1

except EOFError:

[Link]()

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 [Link]

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(“[Link]”,”r”,newline=’’)

freader=[Link](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 [Link] 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
[Link]

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(“[Link]”,”r”)

s=[Link]()

l=[Link]()

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()

[Link]()

You might also like