This python program is working with me, but the only issue i have is that the pr
ID: 3817942 • Letter: T
Question
This python program is working with me, but the only issue i have is that the program can't stop running ( infinite loop )
here is my program
-----------------------------------------------------------------------------------------------------------------------------------------
def main():
input_file = open("mail.dat", "r")
output_file = open("addresses.dat", "w")
line = input_file.readline()
while line !=" ":
line = line.split()
for word in line:
if word.find('@')!=-1:
print(word)
output_file.write(word + " ")
line= input_file.readline()
print(line)
output_file.write(word + " ")
input_file.close()
output_file.close()
#main
main()
Explanation / Answer
Try this:
def main():
input_file = open("mail.dat", "r")
output_file = open("addresses.dat", "w")
lines = input_file.readlines()
for line in lines:
line = line.split()
for word in line:
if word.find('@')!=-1:
print(word)
output_file.write(word + " ")
line= input_file.readline()
print(line)
output_file.write(word + " ")
input_file.close()
output_file.close()
#main
main()
The modified code is highlighted in bold
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.