18515 breaks Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

18515 breaks Python

Hi! I’m new to Python! :D So I wrote the following code: a = 1 while a <= 18515: print(a) a = a + 1 What the code is meant to do is make a line of numbers until it reaches 18515. For example, if I made the code run until 5, it would print: 1 2 3 4 5 But instead, it stops at 539, and prints the following message: “Execution Timed Out!” This happens for all numbers above 18515, but 18514 and all numbers below work. Try it yourself! What I am confused about is: Why does the code stop working at exactly 18515? And why does it print the message after it reaches 539? I am confused, can somebody please answer. Maybe it’s only just me who has this problem.

19th Jun 2020, 8:45 PM
L Rex
L Rex - avatar
4 Answers
+ 3
It really depends what kind of virtual machine your request hits. I "broke" the system and managed to run successfully slightly above 19500 at times and less that 17000 at other times. About the 539 thing - I guess it's the safety valve - whenever the server response is timed out, it just sends a fixed amount (in bytes) of the output, which happens to be cut at this point. EDIT: Leo It happens to be exactly 2kb: https://code.sololearn.com/csu9QVy3Op7h/?ref=app
19th Jun 2020, 9:46 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
If this happens with numbers greater than 18515, it may mean there is an execution time limit imposed to codes run in the platform. If it only happens with 18515, it may be a bug that should be reported.
19th Jun 2020, 8:48 PM
Felipe BF
+ 2
I think the 2kb is the output buffer. IO is normally buffered and 2kb is a typical value for that.
20th Jun 2020, 4:31 AM
Manuel Maier
Manuel Maier - avatar
+ 1
You’re right, as I mentioned the problem happens with everything above 18515 and it might be a limit. But the question is, why did they set the limit to 18515 of all numbers? XD
19th Jun 2020, 8:52 PM
L Rex
L Rex - avatar