+ 1

Time limit exceeded Problem

I've python code thats run well in my machine, but in sololearn playground it returns Time Limit exceeded. What can I do? here's my code: from datetime import * import time fechanueva = datetime.strptime('01/01/2019 00:00:00', '%d/%m/%Y %H:%M:%S') for i in list(range(5)): ahora = datetime.now() print(fechanueva - ahora) time.sleep(1) print("Merry Christmas!!!!")

24th Dec 2018, 10:24 AM
Andros Martínez
Andros Martínez - avatar
2 Antworten
+ 6
You make the code "sleep" for 5 x 1 second, so the whole code will need a little more than 5 seconds to execute. Usually a code has only something like 5 seconds to execute in Sololearn before there is a timeout error. Also note that you can't really use time.sleep() in Sololearn. The whole output is shown at once. So time.sleep() will only make your program slower, but it won't print one line, wait for one second, print another line etc. That doesn't work in Sololearn. By the way, there is no need to convert your range to a list. for i in range(5) does the same.
24th Dec 2018, 10:31 AM
Anna
Anna - avatar
+ 2
Thank you Anna, It's my 3rd python code and I did not know the limitations of the playground. I was trying to implement a countdown
24th Dec 2018, 10:55 AM
Andros Martínez
Andros Martínez - avatar