QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12A-2026-C-29-3-OR #7841

Question:

A. Write a Python function that displays the number of times the word “Python”
appears in a text file named “Prog.txt”.
OR
B. Write and call a Python function to read lines from a text file STORIES.TXT and
display those lines which doesn’t start with a vowel (A, E, I, O, U) irrespective of
their case.

Answer:

A.

def count_python():
count = 0
with open(“Prog.txt”, ‘r’) as file:
text = file.read()
words = text.split()
for word in words:
if word.lower() == “python”:
count += 1
print(“The word Python appears”, count, “times.”)

OR

B.
def display_non_vowel_lines():
with open(“STORIES.TXT”, “r”) as file:
print(“Lines that don’t start with a vowel:”)
lines = file.readlines()
for line in lines:
if line[0].lower() not in ‘aeiou’:
print(line)
display_non_vowel_lines()