2016-10-23 6 views
-1

初心者のプログラマー..とシンプルなSimon Saysゲームをコーディングする。リスト内の項目をチェックする際のトラブル

は、これは私が私の問題は、最初のプロンプトが表示されたら、私は例えば「青」を対応できるということである今現在

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() 

を持っているが、それは、リスト内の2つの色をだ後、IDLEはいつも私が間違って伝えるものです。私は答えを書式設定する方法、またはそれを行うための他の方法を知らない。

答えて

0

ここでは、印刷と比較のために '' .join(s for simon)を使用してみてください。 今は、リストされた印刷物と比較しています。毎回正しく読み取られません。

希望するもの

関連する問題