是否可以在函数中乘以append.input?

时间:2017-05-02 02:31:18

标签: python-3.x function if-statement input

寻求我的功能帮助...

该功能试图帮助用户将他们选择的主题的选择添加到列表中。 它应该询问用户他们想要输入多少选择。必须至少有2个,但如果用户输入的数字> 2,我希望该函数能够为用户生成适当数量的提示输入总选项 - 2(因为该函数假设最少为2),然后继续将输入附加到同一列表中,一旦用户输入所有输入,该列表将在最后返回。 我在最后一部分遇到了问题:"如果数字> 2 ..."我不知道如何调用choice.append(输入(...))数字 - 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

1 个答案:

答案 0 :(得分:1)

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."
        return false

    if number == 2:
        choice.append(input("Please enter the first choice: ")),
        choice.append(input("Please enter the second choice: "))
        return choice

    if number > 2:
        for c in range(0, number - 1):
            choice.append(input("Please enter the next choice: "))
        return choice

    return choice

我会遍历所选择的数字,每次都要求输入