+ 4

Exec() function

So the exec() function will execute a string like a mini program. Can we therefore ask the user to input an entire program. If so, how would we stop the input finishing when the user presses enter? How would the input Finnish?

5th Jan 2018, 8:06 PM
madfighter1359
madfighter1359 - avatar
5 Réponses
+ 9
Perhaps you could make it in a while loop and concatenate until the input equals "end" for example. Like this: https://code.sololearn.com/cK2FvtM6qkGF/?ref=app
5th Jan 2018, 10:01 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 12
Sololearn does not contain all the language interpreters/compilers in-app. Instead, for your code to "run", it sends it to a remote interpreter, which in turn executes your code and sends back the output. Since that is one session per runtime, you have to provide the whole input beforehand.
6th Jan 2018, 7:10 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
I was going to say you could add a new line after each input for longer input but I noticed you've updated it. Thanks
7th Jan 2018, 10:04 AM
madfighter1359
madfighter1359 - avatar
+ 4
Thanks, that works but it raises another question: Is ther any way we could put speech marks on user input to make it last multiple lines in the python shell. It works better on the shell, but why does sololeaen ony let you make 2 lines of input? Maybe the for co fuses it?
6th Jan 2018, 3:07 AM
madfighter1359
madfighter1359 - avatar
+ 2
Thanks
8th Jan 2018, 8:50 AM
andrei