+ 1

Python multiple inputs on a line

How do I take 3 inputs on a line that the program will still run if 1 input was provided

9th May 2022, 10:56 AM
Adekunle Ojekunle
39 Respuestas
+ 1
hobbies = list(input().split())[:3] try: x,y,z = hobbies except: for i in range(3-len(hobbies)): hobbies.append(None) x,y,z = hobbies print(' '.join(map(str,[x,y,z])).replace('None','')) Try this If you would like a better solution tell me exactly what is the problem you are trying to solve by this program . Check it out here and give as many inputs you may like 0-infinite: https://code.sololearn.com/cxGsfiRnNOoM/?ref=app
10th May 2022, 9:22 AM
Anonymous_User
+ 1
Um.... i think he wants to store the first 3 so that he can do something. like he wants to do something with those x , y and z but ignore the extras for now and also he is giving highest priority to the first element . this is just my assumption according to his descriptions and replies.
10th May 2022, 9:43 AM
Anonymous_User
+ 1
Bob_Li well meanwhile my program : 1) He needs 3 optional inputs 2) He needs to store them 3) If they are not provided make them None 4)If a lot are provided just ignore them Meanwhile yours : 1) I just take 1st input into consideration and store it bro why do you forget he said , he needs 3 input in a single line (space seperated) and if only 1 , 2 or 3 or none or more are given the program should still run . But you are forgetting the main point
10th May 2022, 10:08 AM
Anonymous_User
+ 1
Yes , haven't you seen my code it says right at the end that i don't know why someone will need it that way but we have to make what we are asked to 😂
10th May 2022, 10:11 AM
Anonymous_User
+ 1
we just like to climb imaginary mountains. Or set artificial constraints.
10th May 2022, 10:13 AM
Bob_Li
Bob_Li - avatar
+ 1
Anonymous_User Adekunle Ojekunle perhaps it is not about Sololearn input? Maybe he means function that can take arbitrary number of arguments? Then maybe something like this? def print_arguments(*args): for a in args: print(a) print_arguments(1, 'fdgf', '😎') print_arguments(1, 'fdgf') print_arguments(1) print_arguments()
10th May 2022, 10:35 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li we should just leave this topic because " Perhaps there are infinitely many possibilities about what he means " 🤣
10th May 2022, 10:40 AM
Anonymous_User
0
Input with space separated.. After reading split into 3 with space..
9th May 2022, 10:58 AM
Jayakrishna 🇮🇳
0
It won’t run if i use one input, it says (expected3, got 1)
9th May 2022, 11:15 AM
Adekunle Ojekunle
0
Can you share your try here?
9th May 2022, 11:15 AM
Jayakrishna 🇮🇳
0
hobbies, y,z=input(“Enter hobbies:).split() Thats my code, if i input one input, it wont run because its expecting 3 inputs instead of 1, i dont know how to get it to run with only one inputs
9th May 2022, 11:20 AM
Adekunle Ojekunle
0
Adekunle Ojekunle your are using wrong quotes.. hobbies, y,z= input("Enter hobbies:").split() print(hobbies ,y,z)
9th May 2022, 11:29 AM
Jayakrishna 🇮🇳
0
Means? What not way?
9th May 2022, 11:35 AM
Jayakrishna 🇮🇳
0
It was a mistake, if you input only one, it wont run. Thats what i’mtrying to figure out
9th May 2022, 11:36 AM
Adekunle Ojekunle
0
If i input one value, the program won’t run because its expecting 3 inputs not 1
9th May 2022, 11:39 AM
Adekunle Ojekunle
0
Do you need to run on any inputs of 1 to 3 ? Can you tell me what the remaining task with the code ?
9th May 2022, 11:43 AM
Jayakrishna 🇮🇳
0
Yes, i need to run on any inputs, it just has to print any input that is provided either 1,2 or 3
9th May 2022, 11:44 AM
Adekunle Ojekunle
0
You can use this: hobbies = input("Enter hobbies:").split() print(*hobbies) #unpacking into #if you must set 3 variables to default then use try catch.. edit: Adekunle Ojekunle do you aware of try - except blocks?
9th May 2022, 12:12 PM
Jayakrishna 🇮🇳
0
while True: try: print(input()) except EOFError: pass
9th May 2022, 1:23 PM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar
0
سلام
9th May 2022, 6:42 PM
مهدی ملک محمدی معمار