Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote