適切

2017-08-01 11 views
-1
#This program will play a little game 

import random 

secretnames = ([], [], [], [], [], []) 

print('Hi. Please enter your name in letters') 
name = str(input()) 
print('Hi ' + name + '. I am going to play a little game. In this game you have to guess a specific name i am thinking right now.') 
print('But do not worry. I am going to let you to enter 6 names and i will choose one of them.') 
print('After that you have to answer the correct name that i am thinking right now') 
print('Please enter the first name in letters') 
secretnames[0].append(input()) 
print('Please enter the second name in letters') 
secretnames[1].append(input()) 
print('Please enter the third name in letters') 
secretnames[2].append(input()) 
print('Please enter the fourth name in letters') 
secretnames[3].append(input()) 
print('Please enter the fifth name in letters') 
secretnames[4].append(input()) 
print('Please enter the sixth name in letters') 
secretnames[5].append(input()) 
print('Alright ' + name + ' . Thank you for entering the names.') 
secret = random.choice(secretnames) 
for i in range(10): 
     print('Guess a name.') 
     ans = str(input()) 
     if ans == secret: 
       print('Good job. You give the correct answer in ' + str(i) + ' guesses.') 
     elif ans != secret: 
       print('Wrong Answer.') 

これは最初のあなたが好きな名前を入力すると、プログラムはあなたが入力したものの中から名前を決定する必要があると、あなたは彼が正しい名前を入力する必要がスニペットで動作していないスニペット今思っている。私はすべての名前を入力しましたが、誰も働いていません。適切

+0

あなた」のオブジェクトを考えてみて:

secret = random.choice(secretnames) 

秘密はリストを指している。このような文があれば[ 'RandomName']

あなたはあなたを変更する必要がありますre: 'secret'は単一要素のリストであり、入力文字列と同じではありません。 – jonrsharpe

答えて

0

を。

あなたの秘密変数はリストです。 この行の後:

if ans == secret [0]: 
     print('Good job. You give the correct answer in ' + str(i) + ' guesses.') 
    elif ans != secret[0]: 
     print('Wrong Answer.') 
+0

ありがとうございます。あなたは私の問題を解決しました。 –

0

secretnamesは何らかの理由でリストのタプルです。 random.choice(secretnames)は、単独の名前を含むサブリストの1つを返します。

あなただけの単一のリストを使用して、それに追加する必要があります簡単です

secretnames = [] 
... 
secretnames.append(input())