0

How to make while loop work when you need to define a function before accepting input

I just coded a factorial calculator on my python environment on my computer and it runs flawlessly and I was excited to share it, but it gets an EOF error when I try to run it on this site. I read someone else asking about this and they got an answer that you just need to have the inputs at the beginning of the code. The problem I have, is that my while loop repeatedly asks the user for an integer input between 1-1000, which the code will calculate the factorial of. I have some conditions, I have to check if the input was q to quit, which is an option I give, or if it's some other non-integer input that isn't q, which I have to reject and ask again, or check if it's greater than 1000, which I'll again reject and ask again because I don't want to overload memory, and finally, I will call the function and calculate the factorial if these conditions are met. So I have to define the function first before I call it. I can't put the input at the beginning because I would be calling a function that hasn't been defined yet and that would cause an error. Is there no way around this? Why does the input have to be at the beginning?

11th Jan 2025, 6:38 AM
Marlowe Haws
Marlowe Haws - avatar
3 Answers
+ 2
You've discovered one of the limitations with this Sololearn input idea. We're pretty sure they have it this way because of security and load. There's really nothing you can do, other than use another python interpreter. https://www.sololearn.com/discuss/43076/?ref=app https://www.sololearn.com/discuss/855976/?ref=app https://www.sololearn.com/discuss/1249742/?ref=app
11th Jan 2025, 9:34 AM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Marlowe Haws the only way I have found on sololearn to have an interactive input using python is actually using brython or skulpt. Brython is interactive liken to javascript and python together.
11th Jan 2025, 4:27 PM
BroFar
BroFar - avatar
+ 1
Thanks guys, yeah I kinda suspected there wouldn't be a solution. They need to make their site a little better haha.
11th Jan 2025, 5:34 PM
Marlowe Haws
Marlowe Haws - avatar