0% found this document useful (0 votes)
38 views6 pages

Ch.5 - Type C

Uploaded by

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

Ch.5 - Type C

Uploaded by

Prashant Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Q.

Write a program that reads a text file and creates another file that is identical except
that every sequence of consecutive blank spaces is replaced by a single space.

Q. A file sports.dat contains information in following format : Event ~ Participant Write


a function that would read contents from file sports.dat and creates a file named
Atheletic.dat copying only those records from sports.dat where the event name is
“Atheletics”.

Or

Q. A file contains £ list of telephone numbers in the following form:


Or

Q. Write a program to count the words “to” and “the” present in a text file “Poem.txt”.

Or
Q. Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT, should count and display the occurrence of alphabets A and M (including
small cases a and m too).

Q. Write a program to count the number of upper- case alphabets present in a text file
“Article.txt”.

Or

Q. Write a program that copies one file to another. Have the program read the file names
from user?
Or

Q. Write a program that appends the contents of one file to another. Have the program
take the filenames from the user.

Or

Q. Write a program that reads characters from the keyboard one by one. All lower case
characters get stored inside the file LOWER, all upper case characters get stored inside
the file UPPER and all other characters get stored inside file OTHERS.
# Code
f1 = open(‘LOWER.txt’, ‘w’)
f2 = open(‘UPPER.txt’, ‘w’)
f3 = open(‘OTHERS.txt’, ‘w’)

c = True
while c:
c = input(‘Enter a character to write or False to terminate the program : ‘)
if c is False:
break
elif c.islower(): # checks for lower character
f1.write(c)
elif c.isupper() # checks for upper character
f2.write(c)
else:
f3.write(c)
Or

Q. Write a function in Python to count and display the number of lines starting with
alphabet ‘A’ present in a text file ” LINES.TXT”. e.g., the file “LINES.TXT” contains
the following lines :

# Code
def func(l): # function to count lines starting with ‘A’
c = 0 # c is the count of such lines
for line in l:
if line[0] == ‘A’
c += 1
return c

f1 = open(‘LINES.txt’, ‘r’)
l = f1.readlines() # creates a list of all the lines in the file
print(‘Number of lines starting with A in the file LINES.txt is’, func(l))

Or

Q. Write a program that reads characters from the keyboard one by one. All
lower case characters get stored inside the file LOWER, all upper case
characters get stored inside the file UPPER and all other characters get
stored inside file OTHERS.

You might also like