0

How long is "too long" in a Python code?

How would you know, before running, whether your Python code is too long? I get an error stating: "Time limit exceeded" when running my code in the Playground. Clearly it's too lengthy, but I don't understand what constitutes code that is "too lengthy". Is it purely the amount of lines, or the amount of arguments??

24th Jul 2017, 5:39 AM
Dean Carter
Dean Carter - avatar
5 Réponses
+ 2
I believe you get "Time Limit Exceeded" when the memory limit is exceeded. I've seen really long codes, and none of them got any errors, but the error occurs when, for instance, a loop never ends, causing it to break through the memory limit, and you get the error. For instance: while 1<2: print("1") The code above should print infinite ones because 1 is always less than two,but it won't, since you will get the "Time Limit Exceeded" error.
24th Jul 2017, 6:36 AM
Vukašin Zeljić
Vukašin Zeljić - avatar
+ 1
@Vukašin Thanks a lot for your help. Now I understand what the problem was... instead of "returning" values from my if-elif statements, i "printed" them 😂
24th Jul 2017, 6:42 AM
Dean Carter
Dean Carter - avatar
+ 1
@Dean - exactly. :)
24th Jul 2017, 2:26 PM
Bogdan Sass
Bogdan Sass - avatar
0
I think we're talking about an execution time limit, not a memory limit :) . But Vukasin's answer is still correct :)
24th Jul 2017, 11:25 AM
Bogdan Sass
Bogdan Sass - avatar
0
@Bogdan Sass What would constitute an execution time limit? Is it perhaps the fact that the code takes too long to run?
24th Jul 2017, 11:27 AM
Dean Carter
Dean Carter - avatar