Help me, please!


#1


Hi everyone,
I have a problem about my exercise when i try to practice "function" in Python. Below is my code:

def cube(number):
print number ** 3
return number
def by_three(number):
print cube(number)
cube(2)
by_three(3)

And the result which printed in the console is:
8
27
3

I don't understand why number "3" is displayed here. Please explain about this for me. Thanks a lot!


#2

print cube(3)

Inside by_three function you call the cube function with 3 (you called by_three(3))as an argument.and inside cube function you return the number

return number

so number is 3 (you called cube(3))

you can see the number 2 if you call cube(2) with print statement

print cube(2)


#4

I found my problem after your explanation. Thank you so much!


#5

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