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?