Why I didn't get this right?



Hi people,

def distance_from_zero(x):
if type(x) == (int or float):
return abs(x)
return “Nope”

Why I didn’t get this right?
on the hint the answer is:
if type(thing) == int or type(thing) == float:

But I am wondering are there more simple and intuitive way to code?

THank you

if A or B

This implies that A and B are Boolean expressions.

if A == x or B == x

Now both operands of OR are Boolean expressions.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.