Home python reading two numbers from the file and output their sum in another...

reading two numbers from the file and output their sum in another file on python

Author

Date

Category

Two numbers A and B are given. You need to calculate their sum A + B. In this task you need to read from the file and display the answer to the file

input format

The first line of the input file contains numbers a and b separated by a space

output format

In the only row of the output file, output the number A +

Enter input.txt

output output.txt

on Python !!!


Answer 1

def main ():
  With Open ('input.txt') AS F:
    Nums = F.Read (). Split ()
  A, B = MAP (Int, Nums)
  result = a + b
  With Open ('Output.txt', 'W') AS F:
    F.Write (STR (RESULT))
if __name__ == '__main__':
  Main ()

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions