Computer Science
Which of the following is the correct output for the execution of the following Python statement ?
print(5 + 3 ** 2 / 2)
- 32
- 8.0
- 9.5
- 32.0
Python Funda
18 Likes
Answer
9.5
Explanation
According to operator precedence, exponentiation(**) will come first then division then addition.
5 + 3 ** 2 / 2
= 5 + 9 / 2
= 5 + 4.5
= 9.5
Answered By
12 Likes
Related Questions
Predict the output of the following code fragments:
x = "apple, pear, peach" y = x.split(", ") for z in y : print(z)Predict the output of the following code fragments:
x ='apple, pear, peach, grapefruit' y = x.split(', ') for z in y: if z < 'm': print(str.lower(z)) else: print(str.upper(z))How many times will the following for loop execute and what's the output?
for i in range(-1, 7, -2): for j in range (3): print(1, j)How many times will the following for loop execute and what's the output?
for i in range(1,3,1): for j in range(i+1): print('*')