Need help on this lesson
What do you want to know exactly?
this is my code , i don’t know how to multiply three times , i tried * & ** but got refused
def cube(n):
return n**3
def by_three(n):
if n%3 == 0 :
return cube(n)
else :
return False
n = raw_input
finally i’ve solved it
[Code removed by moderator]
please help me on 5/19 Functions Calling Functions please help
spacing
[def cube(n):
tab cubed = n**3
tab return cubed
def by_three(n):
tab if n%3 == 0 :
tab tab return cube(n)
tab else :
tab tab return False
n = raw_input
1st you put the error then your code and wait
i am not sure this is correct chipjumper
return False
n = raw_input
because you need to define the value for function cube
so i believe should be something similar to
cube(10) cube(9) or what ever number you like within ()
but i might be wrong as i am not experienced
I need help. This is my code:
def cube(n):
cubed=n**3
return cubed
def by_three(n):
if n%3 == 0:
print “n is divisible by 3”
return cube(n)
else :
print “n is not”
return False
n=raw_input
I get a error message saying that the “d” in cubed on the second line is an expected an indented block.
I think your indention is off, should be more like
def cube(n):
cubed=n**3
return cubed
def by_three(n):
if n%3 == 0:
print "n is divisible by 3"
return cube(n)
else :
print "n is not"
return False
n=raw_input # Why is this in your program?
def cube(number):
return number ** 3
def by_three(number):
if number % 3 == 0:
return cube(number)
else:
return False
That’s what I have and it passed. Although I notice I returned and modified the argument all in one step. Is that still correct (againit passes) and is it ‘better’ to cube number then call the function ‘cube’ on a new line?
Hey,
i was just wondering why do you have to put the == 0
thanks
Thx, it worked! I dont really know what the “n=raw_input” was. I just saw that someone else had that in their code and it worked for them n i thought i should give it a try
I guess this was highly confusing for most of us :
def cube(number):
cubed = number**3
return cubed
def by_three(number):
if number % 3 == 0:
return cube(number)
else:
return False

cube is not a returned statement, but rather cubed (It is assigned first though).

The second function is defined by
by_three
, whilst the argument is “still”number
. 
The rest is history rather
`
why did you guys input “cubed” for your return?
The argument number
to the power of 3
( number ^3 ) or in python terms number**3
is a cubed
“cube” .
Logically it represents the argument number
cubed
And to answer your question diligently we return
whatever is defined within the function which in this case is the variable cubed
.
More help How is returning the output of a function different than printing it?
Need help on this lesson
You have to do this because the “%” is basically a dividation symbol but instead of the answer being how many times the number goes into a number then whats left is the answer, so 5%3==2 and the == symbol is used for the code to check if both sides match up, so 3%3==0 3 goes into three with no remainder so its zero
This is what I really don’t get: if the value of the variable number is not specified anywhere in the code then how can it return anything? Yet the code worked.
that ‘if’ statement is checking to see if the number is divisible by 3 and no remainder, it uses the modulus (%) to do this and since you are not assigning a value but are testing to see if it’s true, you use ‘==’