Why I didn't get this right?


#1

https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/review-built-in-functions?action=lesson_resume

Hi people,

def distance_from_zero(x):
if type(x) == (int or float):
return abs(x)
else:
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


#2
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.


#3

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