【发布时间】:2017-05-02 02:31:18
【问题描述】:
正在寻求有关我的功能的帮助...
该功能试图帮助用户将他们选择的主题的选项添加到列表中。 它应该询问用户他们想输入多少个选项。必须至少有 2 个,但如果用户输入一个大于 2 的数字,我希望该函数生成适当数量的提示以供用户输入总选择 - 2(因为该函数假定至少为 2),并且然后继续将输入附加到同一个列表中,一旦用户输入了所有输入,该列表将在最后返回。 我在最后一部分遇到问题:“如果数字> 2 ...”我不知道如何调用 choice.append(input(...)) number - 2 次。任何帮助将不胜感激!
def first_decisions2():
number = int((input("Please enter the number of deciding options (eg. 2 or
greater): ")))
choice = []
if number <2:
return "I'm sorry - you didn't enter enough criteria. Please try again."
if number == 2:
choice.append(input("Please enter the first choice: ")),
choice.append(input("Please enter the second choice: "))
return choice
if number >2:
return (number - 2) * choice.append(input("Please enter the next choice: "))
return choice
【问题讨论】:
-
请添加更多描述。很难理解你到底想用你的函数实现什么。
-
稍微改变了我的 cmets。希望这能澄清我的问题。
标签: python-3.x function if-statement input