Why dosent this work


#1

why dosent this work for this exercise?

def divisible_by_ten(num):
if num % 10 == float:
return False
else:
return True


FAQ: Code Challenge: Control Flow - Divisible By Ten
#2

That doesn’t look quite right.

Recall that divisibility is determined by the existence of a remainder, or not. If not, then the number is divisible.

if num % 10 == 0

#3

Could I do a función if ir returns a float result true if not false how would that look with this example


#4

Floats should generally be avoided for any exact operations - testing whether a number is divisible by ten is very much something exact and something that can be tested with only integer math

num % 10 == float

Is wrong because you are comparing a number to a type. In order for something to be equal to a number it will definitely have to be a number too, and float is not a number (it’s not 0 it’s not 5, etc)

Think about what divisible by ten means. You get different outcomes when dividing by ten, what are those two possible outcomes? Do it on paper, think it through before you even bother trying to write anything at all because you most definitely won’t write the right thing if you don’t know what you mean to begin with and the computer doesn’t know what you mean so it won’t “snap” into the right thing either (that’s the programmers job)


#5

If you’re given 52 pebbles you could divide them into ten even piles and see how many, if any, is left.

Does that convince you that it’s possible to figure out if that pile is divisible by ten?

A computer is extremely good at carrying out such tasks accurately and quickly.

A faster implementation is division, it’s the same thing. So you could use that as well, and a bit of thinking about how division relates to those pebbles would tell you how.

As soon as you say the word “float” though, things get out of hand, that’s not related to this problem! (Or were you trying to split those pebbles? Didn’t think so.) No computer-specific ideas are needed while you’re still deciding how to solve something.