+ 1

While loop?

+ This is a bit confusing though, but does sololearn support while loop code? + So, I made a queue program that has a while loop for input in it. I ran it in the terminal and it worked. But when I wanted to publish my code it here I had doubts about how it would work. But it doesn't matter cause' I can handle it. # Then I changed the input system a bit: https://sololearn.com/compiler-playground/cANM43348DoY/?ref=app

29th Jan 2025, 4:56 AM
Kapi
Kapi - avatar
5 odpowiedzi
+ 4
Sololearn can't provide the interactive input feature: The sole place where you can put your input is at that popup when you run the code. You can test your code in other compiles, visual studio code, pydroid 3 (for android) or online python (online)
29th Jan 2025, 7:31 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 4
Hi Kapi, input() returns a string, so x is str, not int. Convert it using int(): x = int(input("Input goes here > ")) To check if x is an integer, use isinstance() and raise an error if needed: if not isinstance(x, int): raise TypeError("x must be an integer") SoloLearn runs code on a server, so input() in a while True loop causes an EOFError.
29th Jan 2025, 8:25 AM
Per Bratthammar
Per Bratthammar - avatar
+ 3
I made this with Acode as text editor and termux to display the output, and it worked 100%, I didn't find any errors at all.
29th Jan 2025, 10:00 AM
Kapi
Kapi - avatar
+ 2
Kapi If you know how many inputs you will be receiving, you can use list comprehension with input(). # num is number of inputs receiving # stores the strings in a list where you can validate each entry later input_list = [input() for x in range(0,num)]
29th Jan 2025, 9:01 PM
Shardis Wolfe
0
You could also the string method isdecimal() to check if a string is an integer before using int() to convert.
29th Jan 2025, 8:49 PM
Shardis Wolfe