gpt4 book ai didi

python - 运行 Python 教程并停留在函数上

转载 作者:行者123 更新时间:2023-11-28 21:16:48 26 4
gpt4 key购买 nike

<分区>

我正在尝试创建一个非常基本的功能,但我似乎做不到。请查看我需要遵循的说明:

  1. First, def a function called cube that takes an argument called number. Don't forget the parentheses and the colon!
  2. Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).
  3. Define a second function called by_three that takes an argument called number.
  4. if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False.

到目前为止我的代码是:

number = raw_input("Enter number")

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

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

请告诉我我做错了什么。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com