Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
25
6
141
24.8K
Navnik | The Vtuber Ginger Coder Shaman
@PythonPr the amount of people confidently stating 10, 14, 18 scares me for the future of software. I had to actually had to run the code myself to see if I was the one going crazy since I knew that if statement with break would exit the while loop before 18 could print.
Navnik | The Vtuber Ginger Coder Shaman tweet media
English
1
0
1
1.4K
Mott & Bow
Mott & Bow@MottandBow·
3 reasons why you’ll love our tees: - They hide your belly and man boobs - They’re luxuriously soft - They’re instant compliment magnets
English
190
303
3.8K
13.6M
Theoden
Theoden@J_Theoden·
@PythonPr Answer is 10 14. The If statement is within the While loop so num == 18 is checked AFTER num becomes 18 but BEFORE it's printed. So the code breaks at num == 18 and 18 is never printed. Output: 10 14
English
0
0
11
1.6K
d_Pythonist 🇵🇸
@PythonPr Code stop at 18 coz num get +4 till it reach 18 where the conditional statement break it
English
0
0
2
575
Manduka
Manduka@mandukayoga·
You show up daily. Your yoga mat should too. The PRO™ Yoga Mat delivers unwavering stability and firm support that protects joints and sharpens balance. Built in Germany. Guaranteed for life.
English
0
25
414
778.8K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
Answer: 10 14 18 Explanation: The loop starts with num = 10 and runs while num < 20. First iteration: print 10 → num += 4 → becomes 14 Second iteration: print 14 → num += 4 → becomes 18 Third iteration: print 18 → num += 4 → becomes 22 Now the if num == 18 check happens after increment, so it never triggers (since num becomes 22). Then the loop condition num < 20 fails, and the loop exits. Key insight: break is never executed because the value skips over the check point after increment.
English
3
0
6
778
Jimmy Fikes
Jimmy Fikes@akajim·
@PythonPr The loop increases num by 4 beginning with 10. So, the loop runs twice and 10 14 will print. After 14 prints, num becomes 18 and the if condition becomes true and break stops the loop. Final output is 10 14
English
0
0
1
419
Paylaş