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
60
20
277
23.1K
Jacob Hess
Jacob Hess@Jacobhess·
I didn’t see the `+=` at first! Whoops!😅 Tip: += means “add the right side to the current value.” So `num += num-5` could be written as: num = num + (num-5) For the example: num = 10 num = num * 2 # now 20 num += num - 5 # add (20 - 5), now 35 print(num) # prints 35
English
1
4
29
1.1K
Yash
Yash@buildwithyash·
@PythonPr Answer is 35 So option c Num = 10 Num = 20 Num = 20+20-5 Num=35
English
0
1
10
732
deby
deby@debbysa23·
@PythonPr C. 35. Num is 10, then 10 × 2 = 20 num += num - 5 means num = num + num - 5, which is 20 + 20 - 5 = 35 CMIIW
English
0
0
5
471
Patrick Dickey
Patrick Dickey@PatrickDickey·
@PythonPr C. num = 10 then num = 20 in the third spot, it adds num (which was 20) to 20 then subtracts 5. Even if you do the portion on the right first, it's still going to add 15 to the original 20.
English
0
0
1
48
Karan
Karan@Karan_Timothy·
@PythonPr 35. Code executes from top to bottom.
English
0
0
1
106
Teerath
Teerath@TeerathJammar·
@PythonPr C - 35 L1 => num = 10 L2 => num = num * 2 L3 => num = num + (num - 5)
HT
0
0
1
203
spark_xyz
spark_xyz@Spark_Xyzz·
@PythonPr The '+= ' assigns a new value to num by incrementing it by 15 thus, ans = 35.
English
0
0
1
85
Alp
Alp@alp_jf·
@PythonPr C Because C is the superior language. 🚬
English
0
0
1
64
Paylaş