+ 1

Hello, is there someone who knows why this code can't go more far away than 1030?

i = 0 while 1==1: print(i) i = i + 1 if i >= 1030: print("Breaking") break print("Finished") Thanks in advance.

29th Aug 2019, 11:16 PM
Javier Balda
Javier Balda - avatar
6 Réponses
+ 1
The problem is not in the code. Sololearn only gives your code 5 seconds to run, so when you overshoot, you'll get that error.
29th Aug 2019, 11:43 PM
HonFu
HonFu - avatar
+ 1
break is used to leave a loop. As soon as i becomes 1030, the while loop is over. I is printed before it becomes 1030, so 1029 will be the last number we see.
29th Aug 2019, 11:37 PM
HonFu
HonFu - avatar
+ 1
Yes, I know but if you write " if i>=1031" the output is "time limit exceeded". In my case. Why?
29th Aug 2019, 11:41 PM
Javier Balda
Javier Balda - avatar
+ 1
Thanks!!! Something strange was happening because I named the code "limit in 1024" and today I tried to know why... And surprise today it can get 1029 and so I did the question. But, I just try again and the limit is 1052.
29th Aug 2019, 11:51 PM
Javier Balda
Javier Balda - avatar
+ 1
The problem was in my title, XD
29th Aug 2019, 11:54 PM
Javier Balda
Javier Balda - avatar
+ 1
Yeah - you could interpret it in two ways. 🙂 The runtime can be slightly different per run. And output changes a lot. Don't print the number and you can go way higher.
29th Aug 2019, 11:55 PM
HonFu
HonFu - avatar