0% found this document useful (0 votes)
60 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)
60 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

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 [Link] contains information in following format : Event ~ Participant Write


a function that would read contents from file [Link] and creates a file named
[Link] copying only those records from [Link] 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 “[Link]”.

Or
Q. Write a function AMCount() in Python, which should read each character of a text file
[Link], 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
“[Link]”.

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(‘[Link]’, ‘w’)
f2 = open(‘[Link]’, ‘w’)
f3 = open(‘[Link]’, ‘w’)

c = True
while c:
c = input(‘Enter a character to write or False to terminate the program : ‘)
if c is False:
break
elif [Link](): # checks for lower character
[Link](c)
elif [Link]() # checks for upper character
[Link](c)
else:
[Link](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 ” [Link]”. e.g., the file “[Link]” 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(‘[Link]’, ‘r’)
l = [Link]() # creates a list of all the lines in the file
print(‘Number of lines starting with A in the file [Link] 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