-2

我是 python 的初学者,我有这个我写的闪存卡游戏的代码。下面的代码只是其中的一小部分。

remove = 0
        while remove < 2: 
            a = random.choice(list(key))    
            if (a) == line27:
                print(a)
                x = input(random.choice(defi))
                x = input(random.choice(defi))
                x = input(line28)

                if x == ('c'):
                    remove = remove + 1
                    print('you got it right')
                    score = (score + 1)
                    print('score =', score)
                if x == ('b', 'a'):
                    print('thats wrong')
                print()
                t = t + 1

                if remove == 2:
                    key.remove(line27)

我必须能够显示这个:

x = input(random.choice(defi))
x = input(random.choice(defi))
x = input(line28)

每次显示时以随机顺序显示。所以这两个随机选择必须显示在不同的位置,第 28 行也是如此。这两个随机选择在一个列表中,如果有帮助的话,第 28 行在另一个列表中。

4

1 回答 1

2

这样的事情就足够了吗?看来这就是您要的,但我真的不知道...

def randomInput(list):
    randIdx = random.randint(0, len(list)-1)
    in = input(list[randIdx])
    list.remove(randIdx)
    return in, list

inputs = [random.choice(defi), random.choice(defi), line28]
x, inputs = randomInput(inputs)
x, inputs = randomInput(inputs)
x, inputs = randomInput(inputs)

另外,正如 Burhan Khalid 所说,x 永远不会等于元组('b','a')......我想你的意思是

x == 'b' or x == 'a'
于 2013-07-04T11:45:26.690 回答