How can I stop the infinite input loop after taking input in sololearn? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

How can I stop the infinite input loop after taking input in sololearn?

Suppose,I have an list name arr which takes input from user and appends to the list. https://code.sololearn.com/cfkTb8W2DRWh/?ref=app Now I can't break out from the infinite while loop after the input is over . Now is it possible to identify when the input is over and break out in sololearn python compiler ?

5th Nov 2022, 4:25 PM
The future is now thanks to science
The future is now thanks to science - avatar
6 Antworten
+ 2
@MATOVU CALEB, In your code, it breaks after taking input for one time but I want to add all the input given by user inside the list and break when user won't give any input. @🧚Somya🌹Yes ,Since I want to take all the input I need to use infinite while loop.To make the loop break, after taking all the input, I need a condition but I don't know what the condition can be. Also yeah, I can break the loop if the user enter a specific command after the input like "end" or something. https://code.sololearn.com/c6gBTIuT3x3N/?ref=app but isn't there a decent conditioning way of not forcing user to enter a specific command after input in sololearn compiler ?
5th Nov 2022, 5:09 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
@ODLNT for some reason, it doesn't work in sololearn compiler : https://code.sololearn.com/c8El5GvAqrSw/?ref=app It looks to me,I need to give a double enter to meet the condition
6th Nov 2022, 3:52 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Well, I've just found a way to do that. To remove the EOF error, we can use a try-except statement to avoid the error. I also need an extra if statement of an empty string to break if someone gives no input. https://code.sololearn.com/c5QbHDBMRq3L/?ref=app it works even though we can't possibly remove the error. Maybe not the best way to do that.
6th Nov 2022, 6:02 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
I used an if statement to check for the type of input https://code.sololearn.com/cz8XF3Y74BL8/?ref=app
5th Nov 2022, 4:48 PM
MATOVU CALEB
MATOVU CALEB - avatar
+ 1
Instead of "exit" use an empty string "", this way all the user have do is press enter when they are done entering names https://replit.com/@CharlesComer/PeskyEasygoingProjects
5th Nov 2022, 5:42 PM
ODLNT
ODLNT - avatar
0
Sorry if I'm late but SoloLearn stores all the inputs in a file, that way you could read from this file like this: https://code.sololearn.com/cMD2d32p6c0t/?ref=app
16th Nov 2022, 11:06 PM
Paulo Eduardo
Paulo Eduardo - avatar