+ 2
Sololearn Input
How do you handle multiple or listed inputs? Here is my perhaps overly complicated way. I'm sure you can think of a better one. https://code.sololearn.com/cjHnzZ4u24gH/?ref=app
7 Answers
+ 3
You can input each value on a new line when giving input. Or you can take input all in one line, split and cast whatever type you want
+ 1
If you have a certain amount of inputs, lets say 4 all on one line.
a,b,c,d = input().split()
then do what you want with each variable
+ 1
Great answer.
If you know beforehand the number of inputs and the user types the input carefully, yes, it is the easiest way.
But sometime we want to deal with indeterminate amount of values, and the user is careless.
+ 1
If it's like that, then you can't guess everything that a user can enter. You can control the input by only accepting correct input. If incorrect input is given, it can let the user know, give an example of correct input, and let them try again. The try again part just couldn't be done here.
+ 1
After searching, I found something:
https://pypi.org/project/smartinput/
it provides input hints and colored text.
But it still needs correctly formatted input values.
And you can't use it in Sololearn.đ
Seems like a good module. Haven't tried it yet
0
line by line works without problem, but wouldn't it need multiple variables? The single line method is my puzzle. How to handle the string if the input is carelessly wonky....
Not really rare if your ui is used by a clueless user.
0
True, I guess what I'm aiming for is a way to handle the input as robustly as possible.
A robust user input is always good. Always returning errors for minor input inconsistencies gives a bad user experience.
With today's tech, a smart input would be a good idea.