0

i = 5 while True: print(i) i = i - 1 if i<=2: 'break'

time limit exceed

17th Apr 2018, 1:46 AM
Elisha Miracle
Elisha Miracle - avatar
10 odpowiedzi
+ 3
how did you do it
17th Apr 2018, 1:50 AM
Elisha Miracle
Elisha Miracle - avatar
+ 3
You can use the code Wolf wrote. It is more efficient. But if you wanted to fix your code with the break statement, firstly know that break is not between quotes. Next, indentations are a very big deal in Python. The code in your question itself puts the if statement out of the loop because it has no indentation so keep that in mind. Here is your code fixed https://code.sololearn.com/cmto9q3RpQ8j/?ref=app
17th Apr 2018, 2:06 AM
cyk
cyk - avatar
+ 2
i=5 while i >= 2: print(I) i -= 1
17th Apr 2018, 1:49 AM
Wolf Web
Wolf Web - avatar
+ 2
☺ I hear that Wolf. That is why I made it clear that your code was more efficient
17th Apr 2018, 2:09 AM
cyk
cyk - avatar
+ 2
:3 it is only logical tho, more compact but still get the same result, that's what I try to teach
17th Apr 2018, 2:11 AM
Wolf Web
Wolf Web - avatar
+ 2
anser 3
19th May 2020, 4:15 AM
Abdelhadi Mastakou
Abdelhadi Mastakou - avatar
+ 1
well, u declare that var, then the statement should be for only while the I is more than two, instead of using a break statement
17th Apr 2018, 1:52 AM
Wolf Web
Wolf Web - avatar
+ 1
make sure the vars are all the same, but other than that, it is correct
17th Apr 2018, 1:54 AM
Wolf Web
Wolf Web - avatar
+ 1
That is Tru, but I try to guide people by the zen of Python, so I try for smaller, but with the same result
17th Apr 2018, 2:08 AM
Wolf Web
Wolf Web - avatar
0
still the same thing showing at the output
17th Apr 2018, 1:53 AM
Elisha Miracle
Elisha Miracle - avatar