+ 1

How can I introduce 2 input values in Phyton?

Hi! First of all, I want apologize for my bad english (my native language is spanish). I want to know how can I use 'input()' with 2 diferents arguments (the text that appears in the screen before introducing any value) for introduce 2 diferents values for 2 diferents variables. For example, if I want introduce a value for X and another value for Y, and I want the texts "Please, introduce the value for X" and "Please, introduce the value for Y", how can I do it? Thank you so much, people!

27th Aug 2017, 4:09 AM
Rhesus
Rhesus - avatar
12 odpowiedzi
+ 3
Unfortunately the SoloLearn user input requires all the inputs to be entered before the input prompts are displayed, so you have to read the code first to see what kind of inputs and how many are required 🙄 In your example, the user must type the X value, hit 'enter' for a new line, type the Y value, and then click 'submit'. If you run the code on a PC IDE, e.g. IDLE or VS Code, or QPython3 on an Android device, each prompt appears before the corresponding entry is required.
27th Aug 2017, 5:26 AM
David Ashton
David Ashton - avatar
+ 3
You could also do: X, Y = input("Please, introduce the value for X "), input("Please, introduce the value for Y ")
27th Aug 2017, 5:27 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
IMC = float(m) / float(h)** 2
27th Aug 2017, 4:43 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
You can use the input function twice, each one for a different input value e.g.: X = input("Please, introduce the value for X ") Y = input("Please, introduce the value for Y ")
27th Aug 2017, 4:47 AM
Amaras A
Amaras A - avatar
+ 1
Also, the value of X and Y will be str because that's what input does
27th Aug 2017, 2:27 PM
Amaras A
Amaras A - avatar
+ 1
🔲
9th Dec 2017, 7:52 AM
Григорий Ли
Григорий Ли - avatar
0
I've tried to introduce the first value, hit enter, and introduce second value but appears the message: "TypeError: unsuported operand type(s) for **or pow(): 'str' and 'int'
27th Aug 2017, 12:19 PM
Rhesus
Rhesus - avatar
0
(Thanks to everyone for the answers)
27th Aug 2017, 12:20 PM
Rhesus
Rhesus - avatar
0
so, how can I convert them? I wrote: {h, m = input("¿Cuánto mides (en ms)?"),input("¿Cuánto pesas (en Kgs)?") float(h) float(m) IMC = m / h ** 2} but it doesn't work
27th Aug 2017, 4:05 PM
Rhesus
Rhesus - avatar
0
h = float(h). Float is an immutable type, and thus it will not modify the variable itself
27th Aug 2017, 4:29 PM
Amaras A
Amaras A - avatar
0
oooh I see. Thank u so much! :D
27th Aug 2017, 4:35 PM
Rhesus
Rhesus - avatar
0
thank u!!
27th Aug 2017, 4:59 PM
Rhesus
Rhesus - avatar