【发布时间】:2021-12-22 12:19:12
【问题描述】:
我有一个需要以下内容的编码作业:
添加一个 main() 函数以从全局空间中删除所有代码
添加至少 1 个从主函数调用的函数。
至少 1 个函数必须接受并使用参数
至少 1 个函数必须返回您的程序使用的值
这就是我目前所拥有的
color = str(input("What color turtle was drawing the shapes? ")).lower()
numofshapes = int(input("how many shapes did it draw? ")).lower()
def whatturtle(color,numofshapes):
if color != "orange":
answer1 = "you are colorblind"
elif color != "blue":
answer1 = "his name is leonardo"
elif numofshapes != 5:
answer2 = "he did not draw that amount of shapes"
elif numofshapes = 5:
answer2 = "he drew some regular polygons with 3,4,6,9,12 sides!"
return answer1
return answer2
#####
def main():
main()
我在这里要做的是让用户说出绘制形状的海龟的颜色是什么以及它绘制了多少个形状(蓝色和 5)我需要在 def main 中使用该函数( ),我该怎么做?我想要得到的输出也是程序说“answer1 and answer 2”(例如,“你是色盲,他没有画那么多形状”)请帮忙谢谢!
【问题讨论】:
-
我已经为我所做的添加了一个更好的解释 + 修复了语句以使用字符串,因为这里不需要 int, + 我不知道你为什么用个人问题编辑你的问题,但你可以通过聊天给我发消息 :) chat.stackoverflow.com/users/12291295/user12291295
标签: python function parameters return