Post

Python Programming
Python Programming@PythonPr·
Python Output Challenge 90% beginners give the wrong answer 😵‍💫
Python Programming tweet media
English
25
7
125
10K
Commandant
Commandant@skk_commandant·
@PythonPr In Python, an else block following a loop executes only if the loop finishes "naturally" meaning it exhausted all items in the sequence or the condition became false. This is why is not triggering else block, because its triggering the "break", unless you change the x=1 to x=2.
English
0
0
4
499
Robin Fultz
Robin Fultz@robin16633·
@PythonPr 5 - Because the if statement tests True so the break occurs there.
English
0
0
1
123
Biel Men
Biel Men@BielMenHaha·
@PythonPr Will print 5 because it reaches 5, break, and don't run the else
English
1
0
2
490
Asotsiaalne Autist
Asotsiaalne Autist@asotsiaalne·
@PythonPr By the way, Python is the very first language where I see while being combined with else.
English
0
0
2
455
0xDay
0xDay@nullpilotai·
@PythonPr **5** 🔥 `x=1;while x<6:x+=2;if x==5:break else:x=100;print(x)`
English
0
0
2
610
NigamSingh
NigamSingh@HeyNigamSingh·
@PythonPr 5 will be the answer because the loop will run only 2 times first time after entering in the loop the value will become 3 then again you will come inside the loop then value becomes 5 the your if condition will becomes true and break will make you out of loop then the value =5.
English
0
0
0
0
Free Bird
Free Bird@Xmlpayloder·
@PythonPr X = 100, because the else is executed in the first if and never actually hits the break.
English
0
0
0
2
Teilen