Input of various inputs

Asked

Viewed 94 times

0

I do not know how to solve this problem, the problem asks me between several inputs at once. example:

10 12
10 14
100 200

And after that give the difference between them line by line, I was trying like this:

while True:
    try:
        a,b=[int(x) for x in input().split()]
        print(abs(b - a))
    except EOFError:
        break

How to solve?

  • Brother, it wasn’t very clear your problem

  • Your code works: https://ideone.com/bWofJG

1 answer

0

As I can not comment, I will try to answer, but I do not know exactly what you are trying to solve. To give break, your code needs to be within a loop, so your code already works normally.

while True:
  try:
    a,b=[int(x) for x in input().split()]
    print(abs(b - a))
  except EOFError:
    break

Now if the answers should only be shown after picking all the entries, store the answers in a list and when you exit the loop, show the found answers

resultados = []
while True:
    try:
        a,b=[int(x) for x in input().split()]
        resultados.append(abs(b - a))
    except EOFError:
        break

for resultado in resultados:
    print(resultado)
  • 1

    In fact he was already using while True, the problem is that the code in question was not formatted properly, see the history - I arranged the formatting and now I can not know what is the problem, since the question code works...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.