-1

Im new to this so i don't quite understand question fully.

It says: It is necessary to load output.txt file in program. Structure of file is that every line is new expression in format:
10-1
6-3.
So format is number-operator-number

It is necessary to write a program that reads that file, line by line, applies the given operation and writes the result together with the associated expression into the file output.txt.

Layout of the output.txt file:

10-1=9
6-3=3

So, were i supposed just to make a new txt document, save it, or write in it 10-1\n6-3 , or within the program make new file 'file'.txt

all i get is what i did input. how to get required output (one at the bottom)?

Thank you for help.

  • There are multiple parts that make up the task. Solve each of them separately. If research doesn't help, extract a [mcve] and include that in a question here. Also, as a new user here, take the [tour] and read [ask]. – Ulrich Eckhardt Nov 16 '22 at 19:22

1 Answers1

0

so i maganed to do it, just to post it so if some1 else might need. Cheers.

f = open("your file location /input.txt")

content = f.read()

splitRows = content.split('\n')

result = ""

for x in splitRows:

a, b = x.split('-') 

c = int(a) - int(b) 

c = str(c) 

res = (a + "-" + b + "=" + c + "\n") 

result += res 

output_file = open("your output file location/ output.txt", "w")

output_file.write(result)