Given the file f, the components of which are integers. Retrieve file g formed from file f with the exception of repeated occurrences of the same number.

Here is my code

import re f = open ("f.txt","r+") n = f.read() nums = set(re.findall('-?\d+', n)) g = open("g.txt","w+") lst=[] for a in nums: lst.append(a) g.write(a) g.close() g = open('g.txt', 'r+') m = g.read() # num1= ', '.join(nums) print("Исходные числа в файле f: ",n) print("Числа в файле g: ",num1) g.close f.close 

The result of the program

 Исходные числа в файле f: 234, -5 , 45, 2, 234, 0, 0 Числа в файле g: 0, 234, -5, 2, 45 

The program works, but you need to redo it so that f.read () is not in the variable n. You also need to make the input numbers in the fc file keyboard. How can I change the code to fix these problems?

Closed due to the fact that off-topic participants Kromster , 0xdb , aleksandr barakin , Enikeyschik , iluxa1810 28 Dec '18 at 7:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, iluxa1810
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • So what is your question? Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. - Kromster
  • Redid a little. In my opinion everything is clear and accessible written - Petr Kurtov
  • You do not ask a question, but ask you to complete the task for you - do you feel the difference? - Kromster

1 answer 1

The program works, but you need to redo it so that f.read () is not in the variable n. You also need to make the input numbers in the fc file keyboard.

Replace:

 n = f.read() 

On

 n = input("Input: ")