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
40
10
180
29.5K
Muhammad Yusuf
Muhammad Yusuf@quarksci·
@PythonPr Correct → 21 while x < 20 means the body executes when x=18 → x=21, then exits. Pro tip: if you want to stop exactly at or before 20, use ≤ or check inside the loop. Drop your strangest while-loop bug below #PythonQuiz #LearnPython
English
0
0
7
618
Jenny
Jenny@JennyTheDev·
@PythonPr B) 21 The loop doesn't stop AT 20, it stops AFTER passing it Just like me scrolling X at 3am, I always go one step too far 💀
English
0
0
7
1.4K
Yon Learning
Yon Learning@yon_learning·
@PythonPr B. 21 because when u loop until 18, it still less than 20
English
0
0
4
2.1K
claveprep
claveprep@claveprep·
@PythonPr Great way to engage the community with Python fundamentals. These quiz posts help reinforce understanding of loop mechanics and variable reassignment. Looking forward to seeing the answer breakdown and learning the reasoning behind each option.
English
0
0
3
946
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr at 18 value becomes 21 condition failed printed (x) value :21
English
0
0
2
338
Othieno Michael Edwards
Othieno Michael Edwards@EdwardsOthieno·
@PythonPr 1. When x = 18, satisfies the condition x < 20 augmented by 3 to increment it to 21 2. Print statement will output 21
English
0
0
2
537
Jamil Alanesi
Jamil Alanesi@jamil_alanesi·
@PythonPr التكرار السادس: x = 15 + 3 → x = 18 هل 18 < 20؟ نعم، استمر. · التكرار السابع: x = 18 + 3 → x = 21 هل 21 < 20؟ لا، توقف عن الحلقة. 3. طباعة القيمة النهائية: print(x) → 21
العربية
0
0
1
500
Sukhman Majri
Sukhman Majri@MajriSukhman·
@PythonPr 21 cause when it’s 18 the loop will continue and add 3 and the next time it’ll not continue as x is 21
English
0
0
0
0
Abenezer
Abenezer@abenezerforcode·
@PythonPr 21, Because, X=x+3, until X lessthan 20 1. 0+3=3 2.3+3=6 3.6+3=9 4.9+3=12 5.12+3=15 9.15+3=18 10.18+3=21, so the while loop will stop and print X, because x>20
English
0
0
0
359
JWCarpenter
JWCarpenter@JWCarpenternet·
@PythonPr this loops adding 3 until it gets above 20 which is 21. 3+3+3+3+3+3+3=21. Math and code ugh
English
0
0
0
0
Jamil Alanesi
Jamil Alanesi@jamil_alanesi·
@PythonPr النتيجة: سيتم طباعة الرقم 21، لأن آخر زيادة جعلت x = 21، وعندها يتحقق أن x لم تعد أقل من 20، فتتوقف الحلقة، ثم تطبع قيمة x النهائية.
العربية
0
0
0
1K
Jamil Alanesi
Jamil Alanesi@jamil_alanesi·
@PythonPr التكرار الثالث: x = 6 + 3 → x = 9 هل 9 < 20؟ نعم، استمر. · التكرار الرابع: x = 9 + 3 → x = 12 هل 12 < 20؟ نعم، استمر. · التكرار الخامس: x = 12 + 3 → x = 15 هل 15 < 20؟ نعم، استمر.
العربية
0
0
0
1.7K
Jamil Alanesi
Jamil Alanesi@jamil_alanesi·
@PythonPr لنتتبع تنفيذ الكود خطوة بخطوة: 1. تهيئة المتغير: x = 0 2. الحلقة while: الشرط x < 20 التكرار الأول: x = 0 + 3 → x = 3 هل 3 < 20؟ نعم، استمر. التكرار الثاني: x = 3 + 3 → x = 6 هل 6 < 20؟ نعم، استمر.
العربية
0
0
0
1.6K
Ron Sperber
Ron Sperber@MathProf·
@PythonPr 21. It starts at 0 and goes up by 3. At one iteration it's 18, but 18 < 20, so it iterates again, hits 21 and exits the loop.
English
0
0
0
31
Teilen