Input of numbers on the same line in python [closed]

0

I need to read three values in a single variable, the third with a comma.

Input: Two rows of data. In each line there will be 3 values, respectively two integers and a value with 2 decimal places. EX: 12 1 5.30 Exit Value: EX: VALUE TO PAY: R $ 15.50

    
asked by anonymous 19.08.2017 / 23:17

1 answer

0

If all were of the same value, it was enough to use the map function that would convert to the chosen type, but as the types and different I believe the only way would be to get them in string and convert later.

Here's a way to do this using split:

a,w,e = input().split(" ") # pega 3 valores na mesma linha e atribui a variáveis

# Converte o valor para os tipos necessários 
a = int(a)
w = int(w)
e = float(e) 

In your case that needs 2 lines just do the same procedure again.

another way and using a list to save all values:

lista = []

lista = input().split(" ")

So all values are in the same "variable", the procedure of converting the values will also be necessary, but in this case I recommend that you only do so at the time of use.

    
21.08.2017 / 13:22