0

Code can't run in sololearn playground!!

I have a simple snippet of code that runs perfectly in my IDE, But when I try it in sololearn playground it produces (no output) Where is the problem???đŸ‘đŸ€“ #! python3 import time import sys indent = 0 # how many spaces to indent indentIncrease = True # whether the indentation is increasing or not try: while True: print(" " * indent, end="") print("*" * 8) time.sleep(0.1) # pause if indentIncrease: indent += 1 if indent == 20: indentIncrease = False else: indent -= 1 if indent == 0: indentIncrease = True except KeyboardInterrupt: sys.exit()

29th Apr 2021, 5:12 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar
4 Answers
+ 4
Program on sololearn runs on a remote server which unlike your machine only allocates limited time for your program to run ( around a second or so ) The problem in your program is that it is exceeding time limit while in the pause state and as the program is terminated like this, the output buffer is not flushed to stdout leading to "no output". The 2 possible fixes of this is to either remove the ( time.sleep() ) from your program or flush the buffer before it. Here is a probable fix 👇 https://code.sololearn.com/csRVa57ys083/?ref=app ( Keep in mind that program will still not run indefinitely because of time limit imposed by SL )
29th Apr 2021, 5:23 AM
Arsenic
Arsenic - avatar
+ 2
It's because your loop is infinite and the only way to break out of it is a keyboard interrupt, which isn't possible in the SL playground.
29th Apr 2021, 5:18 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Awesome, I got it Thank you very much🙏👍
29th Apr 2021, 5:27 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar
0
Thanks🙏🙇 I thought it was because sys module
29th Apr 2021, 5:22 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar