Function Review 19/19


Hi, I was wondering why my code in line 2 would cause me to get the following error message? I have seen the “correct code” having the following but i was wondering if someone could explain why mine wont work.

line 2: if type(num) == int or type(num) == float:


== compares two values. How many values are you trying to compare there?

What you wrote is equivalent to:

(type(d) == int) or float

(Added parentheses to show order of evaluation)


Hi ionathan,

ok, cool, I understand that now - however why would I still be returning the error I am getting?

If i was testing for inputs of strings/ints/floats surely any int/float would still return true? If that is the case, what does it mean when it says " your function seems to fail on input true when it returned ‘1’ instead of ‘Nope’

If it is returning 1 (which is a int) surely this is true for int (-1, 1)



Your function is right half the time, like a broken clock is right twice a day.

You’re not comparing float to the type of d. We went over this D:
What you need to be doing is to compare the type to int, and compare the type to float, and then you combine those results with boolean logic in a way that makes the overall expression true if at least one of the comparisons are true

It’s like expecting your toaster to talk to your water faucet, except neither has wifi or any other networking


Hi Ionatan.

I understand my error clearer now - thank you.

Could you explain the error message though? It seems like if my function was failing for my if statement, it would return ‘nope’ not ‘1’.


Your condition expression always evaluates to something truthy (the value that it evaluates to will be either True, or float, and both of those are truthy)

The input True is not int and it is not float so it should result in 'Nope'

Your function will never return 'Nope' because your condition would have to evaluate to something falsy, which it never does


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