2016-12-16 9 views
-2
number_of_players = int(input("Please input the number of players playing: ")) 
recorded_players = [] 
for counter in range(0, number_of_players): 
    name_of_friend = str(input("Input players first name: ")) 
    recorded_players.append(name_of_friend) 
your_name = str(input("Please enter your name: ")) 
while True: 
    import random 
    random_name = random.choice(recorded_players) 
    if recorded_players != your_name: 
     break 
friend_name = (random_name.upper()) 
selected_name = (your_name.upper()) 
gift_price = (len(friend_name)) * 2 
print(selected_name,"You have bought a gift for your friend", friend_name, "which costs £", gift_price) 

ここで正しい方向に私を指し示すのに役立つ人は誰でも、真のループは私が望むときには壊れません。私が入れたのと同じ名前をつけて、名前が同じでなくても何度も繰り返してループを繰り返し、2人以上のプレイヤーと一緒に作業したいと思います。"true"ステートメントが動作しない

Please input the number of players playing: 2 
Input players first name: Bob 
Input players first name: Alice 
Please enter your name: Bob 
BOB You have bought a gift for your friend BOB which costs £ 6 

あなたは、期待通りのプログラムが動作しないと、私はこの問題の回避策を見つけることができないよう、時間のいくつかを見ることができるように、任意の助けをいただければ幸いです!

+1

。これらの変数はいずれもループ内で変化しません。 –

+0

@gre_gorなので、リストを文字列に変換して動作させる必要がありますか? –

答えて

0

whileループの中では、変更しない2つの変数を比較しています。そして、彼らはまったく異なるタイプです。

あなたはおそらく、あなた自身とあなたのランダムな名前を比較行うためのもの:あなたは文字列にリストを比較している

while True: 
    import random 
    random_name = random.choice(recorded_players) 
    if random_name != your_name: 
     break 
関連する問題