Write a program that reads a file that contains only integers, but some of the integers have embedded commas, as in 145,020. The program should copy the information to a new file, removing any commas from the information. Do not change the number of values per line in the file.

Respuesta :

Answer:

with open("integer_file.txt", "r") as file:

   book = file.read().strip()

   pages = book.split(" ")

   for page in pages:

       if "," in page:

           comma_rm = page.replace(",","")

           print(comma_rm)

       else:

           print(page)

Explanation:

The python program opens a text file (Assuming the file contains only integers but are in string form eg: 5 in '5' for string), reads the whole content of the file as a string, splits it to a list of strings and iterates through to remove commas in the number string and display the elements.

ACCESS MORE