Advertisements
Advertisements
प्रश्न
Write a Python function that displays the number of times the word “Python” appears in a text file named “Prog.txt”.
कोड लेखन
Advertisements
उत्तर
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.")shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
