6. Practice makes perfect, answer?

looking at other people’s coding, you can certainly print the number but the directions didn’t state that. either way it will pass. Programming isn’t always about printing something on your screen. Plenty of programs (functions) running in the background that don’t print on the screen.

1 Like

putting ‘cubed’ was not required but it does make sense to assign that number (which was cubed) a new variable which could be printed to the screen.

def cube(number):
cubed = number**3
return cubed

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

It seems like the def need to have space, othwrise it will not work

Olá.
Devemos prestar atenção ao enunciado, pois deve-se realizar o que se pede:

  • Primeiro, defina (def) uma função chamada cube (cubo) que toma um argumento chamado number (número). Não se esqueça dos parênteses e dos dois pontos!
    Faça essa função retornar (return) o cubo daquele número (ou seja, aquele número multiplicado por si mesmo, e depois multiplicado mais uma vez por si mesmo).
    Defina uma segunda função chamada by_three que toma um argumento chamado number.
    Se (if) esse número for divisível por 3, by_three deve chamar cube(number) e retornar seu resultado. Caso contrário, by_three deve retornar falso (return False).

Observe que a função (cube) deve retornar o cubo de (number)!

Então podemos observar o seguinte comportamento:

def cube(number):
return numbernumbernumber

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

2 posts were split to a new topic: 6. What have I done wrong

A post was split to a new topic: 6. Your function fails on is_prime(1). It returns True when it should return False

A post was split to a new topic: 6. Did you define a function called by_three?