7 Réponses
+ 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 )...
+ 2
Post your code if you want attempt to help ^^
+ 1
Did you test it on a PC?
0
Yes, and i also tested it on a python3 shell emulator for android (since i use android).
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
0
It appears bad formatted here...
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.