检查列表中的项目有问题

时间:2016-10-23 21:44:27

标签: list python-2.7

第一年介绍程序员..并编写一个(不那么)简单的Simon说游戏。

这就是我目前的

import random

    #the items (colors) that Simon can choose from
colors = ['Red', 'Blue', 'Yellow', 'Green']

    #A list for what Simon's pattern can be in
simon = []

    #A list for what the User's pattern can be in
user = []

def SimonSays():
#Choose a random item in the list of colors
    simon.append(random.choice(colors))
#for each item in the list, or each color in the list 'simon', print that list
#this is just for testing to see what the color is
    for color in simon:
        print simon
    userResponse = raw_input("What did Simon Say?")

#if the user responded with the correct color
    if userResponse == color:

#IDLE will print.. then add another color to the list, and prompt the user again
        print "Correct, a new item will be added to the sequence"
        twoColors = simon.append(random.choice(colors))
        print simon
        user2Response = raw_input("What did Simon Say?")

        if user2Response == simon:
            print "Correct"
        else:
            print "Incorrect"


#if the user didn't respond with the correct color..       
    else:
        print "Incorrect, sorry you lost."



SimonSays()

现在我的问题是我可以回复“蓝色”'例如,当第一次提示时,但一旦它在列表中有两种颜色,IDLE总是告诉我不正确。我不知道如何格式化答案,或其他任何方式。

1 个答案:

答案 0 :(得分:0)

这是一个提示尝试使用''.join(s for s in simon)来打印和比较。 现在您正在与列出的打印进行比较,每次打印都会读取错误。

希望有所帮助