+ 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!
12 Respostas
+ 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.
+ 3
You could also do:
X, Y = input("Please, introduce the value for X "), input("Please, introduce the value for Y ")
+ 3
IMC = float(m) / float(h)** 2
+ 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 ")
+ 1
Also, the value of X and Y will be str because that's what input does
+ 1
🔲
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'
0
(Thanks to everyone for the answers)
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
0
h = float(h). Float is an immutable type, and thus it will not modify the variable itself
0
oooh I see. Thank u so much! :D
0
thank u!!