Input numbers in the same line in python

Asked

Viewed 24,100 times

1

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

Input: two data lines. In each row there will be 3 values, respectively two integers and a value with 2 decimal places. EX:12 1 5.30 Output value: EX: AMOUNT PAYABLE: R$ 15.50

  • Describe the problem better

  • You are a beginner?

  • Yes @nelson450, I’m a beginner. I switched to improve understanding.

  • Please give examples of what this entry will look like and why you need to store it in just one variable.

  • Take a look at this link.

1 answer

2


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

Here’s a way to do it using the 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 you need 2 lines just do the same procedure again.

another way and using a list to store all values:

lista = []

lista = input().split(" ")

So all the 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 it at the time of use.

Browser other questions tagged

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