0
I dont vert understand how works input() fonction, like how can I get multiple of them ?
7 Respostas
+ 1
For example, if you have a code:
x = input()
y = input()
z = input()
only one input box will pop up when you run the code. But each line of your input in the box will be unpacked to each variable assigned to input() function in order of their assignment.
So if the input box pops up and the user inputs;
>>>
Hi
Sololearn
I Love your code play ground
>>>
This will mean x = 'Hi'
y = 'Sololearn'
z = 'I Love your code play ground'
This is because of the multiple lines. Each line in the input box is seen as an input() function call.
Hope it helps.
0
Yes it help a lot. Thank you very much. The people in sololearn are awsome !
0
You're welcome...
0
Sorry, but I have another little question : how can we input "int" or "float" instead of "str" ? In this code I try to input number, like '100/3', but it doesnt work because it says that we cant convert "100/3 in Float...
https://code.sololearn.com/cu0qFf3tCdp1/?ref=app
0
There are are number of ways to get over that.
#1
#let the user separate each with a white space. e.g.
#code:
a = input().split()
print(float(a[0]) / float(a[1]))
#input
100 4
#output
25.0
#2 Let the user separate each with a new line. e.g.
#code:
a = float(input())
b = float(input())
print(a / b)
#input
100
4
#ouput
25.0
#3 using eval() function. But this is not advisable as it is not a safe method.
0
Ok that exactly what I need thank you ! I had check some of ure code and I very apreciat them, especially the translate "base 10 to another base"
0
You're welcome