Is something wrong with python editor? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is something wrong with python editor?

When i am trying to run a correct code in code playground while using python lang it hits the following error: Time limit exceeded. Why does this error pops up? Is something wrong in this use case of the app?

9th Jan 2017, 3:33 AM
RottenCrab
RottenCrab - avatar
7 Answers
+ 3
Copy-paste loose sometimes/often information of new lines, tab... Your problem of time limit execeed in code playground is because your script keep too long to run totally: if you decrease the 'timer' limit ( 50, without sleep pass, 75 not, even without the sleep ) the problem disappear. The trick is that your line: print(string[:pointer] + string[pointer].swapcase() + string[pointer + 1:], end="\r") ... is asking for a lot of ressource ( relativly, but at each execution you are entirelly duplicate an array + temporary internals copies to achieve that ), multiplied by the 'for' loop on each string character, and again multiplied by the 'while' loop. You may test if using slice/splice fonctions could improve the speed of your script... but not sure. Another possibility is to buffering you text to print, and print it once ( print is high ressource consumers, and all the more so with distant execution -- as well as SoloLearn collect only one string for the output, and send/display it at whole once )...
9th Jan 2017, 4:46 AM
visph
visph - avatar
+ 2
Post your code if you want attempt to help ^^
9th Jan 2017, 4:17 AM
visph
visph - avatar
+ 1
Did you test it on a PC?
9th Jan 2017, 3:54 AM
Dao
Dao - avatar
0
Yes, and i also tested it on a python3 shell emulator for android (since i use android).
9th Jan 2017, 4:09 AM
RottenCrab
RottenCrab - avatar
0
from time import sleep string = "funny string show!" timer = 0 while timer < 200: pointer = 0 for _ in string: print(string[:pointer] + string[pointer].swapcase() + string[pointer + 1:], end="\r") pointer += 1 sleep(0.05) timer += 1
9th Jan 2017, 4:18 AM
RottenCrab
RottenCrab - avatar
0
It appears bad formatted here...
9th Jan 2017, 4:19 AM
RottenCrab
RottenCrab - avatar
0
That was helpful. But it concludes to the fact that codeplayground is a bit buggy since it cannot manage resources successfully. Furthermore i managed to make this run (with appropriate modification) and i spotted another bug, special character \r (return cariage) is not work as it should. It displays the printed output in several lines instead of one while erasing the previous printed output. Anyway, thanks for your help.
9th Jan 2017, 10:35 AM
RottenCrab
RottenCrab - avatar