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
54
14
291
30.2K
Mack Shonayi
Mack Shonayi@mackshonayi·
@PythonPr The answer is C. Because r = p + str(q) is concatination, it gives us => 414 Then 414/2 = 207.0 because in Python division(/) always returns a flot result. Even when dividing with only integers
English
2
1
14
822
Slinxs
Slinxs@JSlinxsx·
@PythonPr The correct output is: ✅ (C) 207.0 Explanation: ☑️ String concatenation + type casting + float division combine to yield a floating-point result.
English
0
1
10
1.2K
#!/usr/bin 🇮🇳
#!/usr/bin 🇮🇳@iamjogi·
@PythonPr C. By default, the type returned by division is 'float'. If you want integer division, convert the expression to int.
English
1
0
8
943
Manish Khyalia
Manish Khyalia@Manish_Kumar60·
@PythonPr Answer:-(C)207.0 r= p + str(q) means first convert q into string then concatenate p and q. So r= "414". s = int(r) / 2 means first convert r into integer then divide by 2. The result of int/int is float in python. So final answer is 207.0
English
0
1
6
680
TOYO
TOYO@Babzcode·
@PythonPr 207 - That was my initial answer until I actually run the code. So, I'm curious if anyone can explain why it returns 207.0
English
1
0
4
1.8K
Bassem
Bassem@Bassem_Oman·
@PythonPr C. ✅ print(414//2) 207
Français
1
0
3
289
R. Stephen Ruiz
R. Stephen Ruiz@rslruiz·
@PythonPr Ans. c) 207.0 r = '414' int(r) -> 414 s = 414 / 2 = 207.0 # type(s) is float
English
0
0
1
413
Biel Men
Biel Men@BielMenHaha·
@PythonPr The division returns a float. 414÷2=207.0
English
0
0
1
235
Alex Matías
Alex Matías@alexmatiasas·
@PythonPr r is a string '4' + '14' = '414' Then casts to an int but a fraction is always float so it goes to 414 / 2 as a float = 207.0 (c)
English
0
0
1
416
Prathish . S
Prathish . S@PrathishS45·
@PythonPr Option a Concatenate p and q and change string to integer and it is divided with 2 Store in r
English
0
0
0
111
Paylaş