+ 5

How to enter two or more input in python in Sololearn?

name = input () age = input () print (name, age)

10th Feb 2024, 5:25 AM
Manish
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)
10th Feb 2024, 3:24 PM
Andrey 🐯
Andrey 🐯 - avatar
+ 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/
10th Feb 2024, 7:01 AM
Lothar
Lothar - avatar
+ 6
aName 19
10th Feb 2024, 6:57 AM
JaScript
JaScript - avatar
+ 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.
11th Feb 2024, 7:16 AM
Lothar
Lothar - avatar
+ 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.
14th Feb 2024, 1:50 AM
Rain
Rain - avatar
+ 2
I do not give any answer but it is my question.
10th Feb 2024, 11:32 AM
Manish
+ 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
14th Feb 2024, 12:02 PM
Rain
Rain - avatar
+ 1
Understood
10th Feb 2024, 1:16 PM
Cofelub
Cofelub - avatar
+ 1
Andrey 🐯 Thank you so much. It is working.
10th Feb 2024, 3:28 PM
Manish
+ 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
10th Feb 2024, 4:56 PM
Black White tears
Black White tears - avatar
+ 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(',')
11th Feb 2024, 7:53 AM
Jomari Tenorio
Jomari Tenorio - avatar
0
age_name = list(input()) print("".join(age_name))
10th Feb 2024, 9:09 AM
Cofelub
Cofelub - avatar
0
AT THE END try something like, print(name + age)
11th Feb 2024, 5:31 AM
Rutvik Muniraja
Rutvik Muniraja - avatar
0
Age , name = input() print(name,age) If you want to be in one line just use split()
11th Feb 2024, 6:21 AM
Fateme Biglari
Fateme Biglari - avatar
0
Use while to input more than 2 input
11th Feb 2024, 12:11 PM
Debraj Mandal
Debraj Mandal - avatar
0
Salut
11th Feb 2024, 5:39 PM
Boubacar Baldé