CBSE Class 11 Computer Science Question 126 of 173

Data Handling — Question 15

Back to all questions
15
Question

Question 11

Find out the error and the reason for the error in the following code. Also, give the corrected code.

a, b = "5.0", "10.0"
x = float(a/b)
print(x)

Answer

a and b are defined as strings not float or int. Division operator doesn't support strings as its operand so we get the error — unsupported operand type(s) for /: "str" and "str".

The corrected code is:

a, b = 5.0, 10.0
x = float(a/b)
print(x)
Answer