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()
In the code (given above), the word END used to indicate end of word list is also stored in the file. Modify the code so that end is not stored in the file.
कोड लेखन
Advertisements
उत्तर
with open("textfile.txt", "w") as file:
while True:
word = input("Enter a word (END to quit): ")
if word.upper() == "END":
break
file.write(word + "\n")
The termination test is performed before write(), so END is not stored.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
