Advertisements
Advertisements
प्रश्न
file = open('textfile.txt','w')
word = ''
while word.upper() != 'END':
word = raw_input('Enter a word use END to quit')
file.write(word + '\n')
file.close
Using the file mentioned above, write a function to read the file and display numbered list of words.
कोड लेखन
Advertisements
उत्तर
def display_words():
with open("textfile.txt", "r") as file:
number = 1
for word in file:
print(number, word.rstrip("\n"))
number += 1
display_words()
Each line is read sequentially and displayed with its serial number.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
