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
48
7
119
23.1K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Supposed to be an error, Nonetheless the answer is supposed to be 6 Why is it 6? Here's the breakdown; You are creating a list named x that contains three integer elements.sum(x): The sum() function is a built-in Python utility that iterates through an iterable
English
1
0
7
539
Tanmay Newatia
Tanmay Newatia@thetanmaydoes·
@PythonPr Error courtesy of unclosed parenthesis in the print statement
English
0
0
6
1.4K
The root of infinity
The root of infinity@parth_hirpara05·
@PythonPr Ans--->(C)Error There’s a missing closing parenthesis ) in the print statement, so Python raises a SyntaxError
English
0
0
2
867
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: A) 6 sum() adds all numbers in a list: › sum([1, 2, 3]) › 1 + 2 + 3 = 6 For beginners: sum() works on any iterable of numbers. Can also set start: sum([1,2, 3], 10) = 16
English
1
0
2
1.8K
Jenny
Jenny@JennyTheDev·
@PythonPr A) 6 sum() adds all elements in the list: 1 + 2 + 3 = 6 The trick here is that sum() works on iterables, not strings - so no concatenation happening
English
1
0
2
1.5K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output C) Error ✅ Because the code is missing a closing parenthesis: print(sum(x) ➜ should be print(sum(x)) So it throws: SyntaxError: '(' was never closed
English
0
0
1
556
Python Tech
Python Tech@PythonTech43716·
@PythonPr B) 6 is the right answer. Just use the sum function here and simply add of all the numbers present in list.
English
1
0
1
141
Kay
Kay@tigerkay2free·
@PythonPr C) Error
Français
1
0
1
1.5K
Othieno Michael Edwards
Othieno Michael Edwards@EdwardsOthieno·
@PythonPr 1. The print statement is missing a closing parentheses therefore a SyntaxError results 2. Barring that the result would be 6
English
0
0
1
208
ExamAdda
ExamAdda@examaddaorg·
@PythonPr The code is: python x = [1, 2, 3] print(sum(x) Answer: SyntaxError (missing closing parenthesis ) ) That's why → C is correct.
English
0
0
0
8
Blarghanghast
Blarghanghast@blarghanghast·
@PythonPr The answer is A. sum() takes all numbers within the list, then adds them together.
English
0
0
0
43
Pat. C. Obiorah
Pat. C. Obiorah@pat_obiorah·
@PythonPr error. Missing closing parenthesis at print.... The print function should be closed print()
English
0
0
0
59
Joe McCane
Joe McCane@joesavage90·
@PythonPr This happens to me all the time when vscode forgets to do the work for me haha. Its an syntax error, missing parentheses lol
English
0
0
0
579
@CodeTech
@CodeTech@Y73151296Anurag·
@PythonPr Actually there is a missing clossing bracket ): And than right answer is 6.
English
0
0
0
71
bb20
bb20@bb2001o·
@PythonPr Error missing parentheses !
English
0
0
0
26
Kawazu Biscotti
Kawazu Biscotti@Kawazu_874·
@PythonPr Interpreter told me 6 . Because I had no idea it could do that :)
English
0
0
0
45
Adichareh M
Adichareh M@Adichareh·
@PythonPr Error, print statement is not closed print (sum(x) Should have been print (sum(x))
English
0
0
0
85
Paylaş