虽然没有要求两次输入

时间:2014-12-26 15:30:05

标签: python

scenario2(results)函数调用sget_choice3,因此它根据用户选择打印结果。

如果Users选项为0(正确的一个是1而0只是它的一个分支),我希望函数循环并请求输入两次。

s2option_list3 =['Try to force it', 'Examine the door']

    def sget_choice3(s2option_list3):
        i = -1
        while i <= 0:
            print s2option_list3
            choice3 = raw_input("> ")
            for i, opt in enumerate(s2option_list3):
                if opt in choice3:
                    i = i + 1
                    return i 
                else:
                    i = i + 2
                    return i             

            print "You need to select one of the given actions"

def scenario2_exit(outcome): 
    print outcome
    choice = outcomes[0]

    if outcome in choice:
        print "conversation"

        res3 = sget_choice3(s2option_list3)

        if res3 == 0:
            print "You try to force it but without any luck. However you do notice a little button on the left corner. "

        else:
            print "A small panel comes out, seems to be requesting a code. " 
            print "conversation"            

    else:
        print "conversation"

1 个答案:

答案 0 :(得分:1)

您的问题似乎在这一行:

for i, opt in enumerate(s2option_list3):

当您使用enumerate时,它会使用枚举的索引覆盖i(当时为-1)的值(0为第一个选项和第二个1。我不确定你为什么要尝试使用枚举。

如果没有给出太多关于如何重构程序的建议,一个简单的修复可能是这样的:

for opt in s2option_list3:
相关问题