PLZ help!


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096

File "python", line 3
def by_three(number)
^
SyntaxError: invalid syntax


def cube(number):
    return number ** 3
def by_three(number)
    if number == 3:
        return cube(number)
    else:
        return False


#2

Your problem is that you didn't use a colon on this line

to introduce the beginning of a function.
Additionally, the logic of your program is wrong.

should actually be if number % 3 == 0
because you're checking for divisibility, not if the number is equal to three.


#3

Thank you. Tbh i didn't know how to determine if a number is divisible by something so thank you.


#4

To check if a number is divisible by something, you first need to know the definition of divisible. It means to be able to be divided by another number without a remainder left over. This means that you need to check if the remainder is 0, right? To do this, you use the modulus/modulo operator, %, and what it does is returns the remainder.
Where 10 / 2 is 5, 10 % 2 is 0.
It's actually a mathematical operator that uses division that we don't see much of.
Other examples are 10 % 3 is 1 because 1 is left over.
I hope this helps! We use modulus often in programming.


#5

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