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
29
10
77
9.3K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr This is a classic "gotcha" question! If you're looking at the logic the creator intended, the answer is C (120). However, if you're looking at how Python would actually behave, the code is full of traps. Here is the breakdown of why this code is trickier than it looks:
English
2
0
8
796
Jay
Jay@learnaiwthme·
@PythonPr The condition x > 20 filters the list and keeps only 30, 40, 50. Then sum() adds them together: 30 + 40 + 50 = 120 So the correct answer is C) 120.
English
0
0
3
235
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: C) 120 Step by step: › Filter: x > 20 (30, 40, 50) › sum(30, 40,50) = 120 For beginners: "if x > 20" filters the list first, then sum() adds them up.
English
0
0
2
323
Siddartha DevOps
Siddartha DevOps@SiddarthaDevops·
Answer: C) 120. Step by Step Explanation: The list is [10,20,30,40,50] the generator expression x for x in nums if x>20 filters only numbers greater than 20. that gives [30,40,50] sum(30+40+50) adds them up: 120 print(results) outputs : 120
English
0
0
2
399
Abdullah Munib
Abdullah Munib@munibcodes·
@PythonPr C) 120 Only values > 20 are summed → 30 + 40 + 50 = 120.
English
0
0
1
128
Pat Garner
Pat Garner@patgarner·
@PythonPr barring the typo, the answer is c) 120
English
0
0
1
203
cloudmountain. wang
cloudmountain. wang@PythonHand·
@PythonPr None of the selections because X is capital letter in line 2, and X is not declared.
English
0
0
1
194
Dr. Pablo KODAMA
Dr. Pablo KODAMA@PABLOKODAMA·
@PythonPr Actually, the code cannot run "print(resutt)" kkkk. Adding "resutt=result" before print, the code will add all the numbers of the list "if" the number is bigger than 20. The result is 120 ( 30+40+50).
English
0
0
0
0
Joe McCane
Joe McCane@joesavage90·
@PythonPr C - 10 and 20 are dropped as they are not bigger than 20
English
0
0
0
54
Não me Intica
Não me Intica@realnaomeintica·
@PythonPr raised exception because X (capital) is not defined
English
0
0
0
27
Teilen