How do I get the input to be on the same line?

Asked

Viewed 68 times

0

I wish that when someone comes in, the input stays on the same line, I tried using the 'split' command, but I could not.

D = int(input())
R = int(input())
L = int(input())
P = int(input())
G = int(input())
autonomia = L * 10
km = (D - autonomia) / 10
gas = km * G
distancia = D // (P + 1)
if D <= autonomia:
   print('Pode viajar\nR$: {}'.format(int(R - gas)))
elif D >= distancia and R >= gas:
   print('Pode viajar\nR$: {}'.format(int(R - gas)))
elif D >= autonomia or distancia and gas > R:
   print('Não pode viajar')
  • 2

    That? https://answall.com/q/427259/101 or https://answall.com/q/346650/101 or https://answall.com/q/149/101 or https://answall.com/q/454645/101 or a 50 that you already have on the website about it. I do not know if it is written that this is not a good idea, but it should. I do not know why to exchange the simple for the complicated.

  • It’s simple, a question in The Huxley wants it that way.

1 answer

0


You can use map, split and multiple assignments. As shown in the example below:

D, R, L, P, G = map(int, input().split())

Split:

is a method that returns a list from a string.

Map:

executes a function specified for each item in an iterable. The item is sent to the function as parameter.

The multiple assignment in this case is limited to 5, as it is the number of variables that we pass to the left side of the =.

  • 1

    Cool! But why does it work? Could you explain it in a little more detail? Learn more about how to elaborate a good and well explained answer here.

  • It works because the split will 'create' a list with the entries separated by space. Then the map will apply to this iterable (the list created by the split) and will convert to integer.

  • 1

    I think it’s also worth explaining about the multiple assignment, and the fact that in this case the input must have exactly 5 numbers to work

Browser other questions tagged

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