Practice Makes Perfect


#1



1. What Good are Functions?
6. Practice Makes Perfect

Why when i change the % for a / it says that "by_three(1) returned 1 instead of False"


def cube(number):
    return number**3

def by_three(number):
    if number % 3 != 0:
        return False
    else:
        return cube(number)


#2

@ajaxplayer13275:

print 1/2 # 0

print 1%2 # 1 <- remainder of the division

A better explanation:
The module operator, %, will bring back the remainder of a division between numbers, regardless if they're integers or float numbers.

While the slash operator, /, calling it this way since I have no idea what's the actual name of it, will bring the quotient of the division.

Q: So what's happening with my code is ...
A: Instead of checking if the reminder of a number by 3 is equal to zero, you're just checking the remainder of it.


#3

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