練習1
- def a function called cube that takes an argument called number.
- make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).
- def a second function called by_three that takes an argument called number.
- if that number is divisible by 3, by_three should call cube(number) and return its result.
- otherwise, by_three should return False.
def cube(number):
return number * number * number
def by_three(number):
if number % 3 == 0:
return cube(number)
else:
return False
print(cube(2))
print(by_three(3))
print(by_three(4))
8
27
False