KnowledgeBoat Logo

Computer Science

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)

Python Data Handling

23 Likes

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)

Answered By

12 Likes


Related Questions