+ 5
How to enter two or more input in python in Sololearn?
name = input () age = input () print (name, age)
16 ответов
+ 6
name, age = input("Enter your name and age separated by a space ").split()
print("\n")
print("My name: ", name)
print("My age: ", age)
+ 9
Manish ,
suppose the name is `tom` and the age is `42`.
in your case the 2 input lines in the popup window should be:
tom (press enter on keyboard)
42 (press submit in popup window)
btw: following the python style guide (pep-0008) function call in python should be written *without* spaces between the function name and the parenthesis.
>> https://peps.python.org/pep-0008/
+ 6
aName
19
+ 5
just to mention that samples with giving input in *one line with splitting* the input is working (if it is implemented properly) in your own coding tasks.
however, it does *NOT* work if it is a *code coach exercise* that expects multiple individual inputs.
+ 3
# Andrey 🐯 ,
# Cool. str.split() makes a list.
# For some reason, I had "learned"
# the rule that you can do multiple
# assignments from a tuple.
a, b = (5, 6) # parentheses optional
# As in the pythonic swapping idiom.
a, b = b, a
print(a, b) # 6 5
# But it's apparently possible
# from any iterable.
a, b, c = range(10, 40, 10)
print(a, b, c) # 10 20 30
# Now I know.
+ 2
I do not give any answer but it is my question.
+ 2
Andrey 🐯 ,
I figured out where I got the wrong idea that multiple assignment was just for unpacking tuples.
Python Intermediate has a few pages on what they call "tuple unpacking" (because they demonstrate it with a tuple), but they neglect to reveal it's just one type of what the docs call "sequence unpacking".
I wrote a tiny test of each type.
https://sololearn.com/compiler-playground/crcuMRjNnEfI/?ref=app
+ 1
Understood
+ 1
Andrey 🐯 Thank you so much. It is working.
+ 1
while entering the nums
use spaces or enters as a seperator
so when you're giving the code inputs as intigers the code will know that the first number before ( space or enter ) is for the first input and so on
+ 1
Depends on your approach.
If you want the input to be separated by comma or space just do this
x, y = input().split(' ')
or
x, y = input().split(',')
0
age_name = list(input())
print("".join(age_name))
0
AT THE END try something like,
print(name + age)
0
Age , name = input()
print(name,age)
If you want to be in one line just use split()
0
Use while to input more than 2 input
0
Salut