2016-08-09 7 views
1

私はPythonで新しいです。私はこのウェブサイトTheHelloWorldProgram.comを見つけたので、わかりやすいtictactoeのゲームを書く方法を教えてくれましたが、何か問題がありました。私はこの構文エラーメッセージ "無効な構文"を取得し続け、それはplayer = Falseを指していました。 「選手」を強調表示しました。どうして?私はそれを理解できませんでした。助けてくれてありがとう。以下は、ゲームのコードが表示されます。#コメントは申し訳ありません。彼らは、自分のためにある:Python、tictactoe、構文エラー

#importing randint from the random module 
from random import randint 

#create a list of play options 
1 = ['Rock', 'Paper', 'Scissors'] 

#assign a random play to the computer 
computer = t[randint(0,2)] 

#set player to False 
player = False 

while player == False: 
    #set player to True 
    player = input("Rock, Paper, Scissors?") 

#if player = computer, it is a Tie! 
    if player == computer: 
     print("Tie!") 

#else if player = ROCK 
    elif player == "Rock": 
     #computer = paper 
     if computer == "Paper": 
      #player lost, paper beats rock 
      print("You lose!", computer, "covers", player) 
     else: 
      #player win, rock beats scissors 
      print("You win!", player, "smashes", computer) 

#else if player = PAPER 
    elif player == "Paper": 
     #if computer = scissors 
     if computer == "Scissors": 
      #player lost, scissors beats paper 
      print("You lose!", computer, "cut", player) 
     else: 
      #player win, paper beats rock 
      print("You win!", player, "covers", computer) 

#else if player = SCISSORS 
    elif player == "Scissors": 
     if computer == "Rock": 
      print("You lose!", computer, "smashes", player) 
     else: 
      print("You win!", player, "cut", computer) 
    else: 
     print("That's not a valid play. Check your spelling!" 

    #player was set to True, but we want it to be False so the loop continues 
    player = False 
    computer = t[randint(0,2)] 
+2

'print("これは有効な演奏ではありません。スペルを確認してください! "' '< - ' missing closed括弧 –

+0

5行目の1列目に '1'ですか?(空白行とコメント行。 – Wickramaranga

+0

ジムとウィックありがとうございましたあなたは頭の上で釘を打ちました。最も感謝しています1は可変であることを意味しました – Vuken

答えて

2

1 = [「ロック」、など] Tが基準Python用 を=(と私はほとんどの言語を考える)である必要がありますがT1を行うことができ 変数名として#を受け入れません、t_1、t、1、しかし1t、1_t ,.したがって、数値で始まる数と変数。 @Wickramarangaが指摘したように。

と@ Jimは、あなたのプリントステートメントを閉じると指摘しました。 Pythonエラーをチェックする良い場所は、エラーが指すステートメントの前のステートメントです。プレイヤー= Falseに

print("That's not a valid play. Check your spelling!" 

#player was set to True, but we want it to be False so the loop continues 
player = False 

あなたのエラー箇所を、Pythonインタプリタが

print("That's not a valid play. Check your spelling!" 

それはエンディング見ませんでしたが「)」を実行したため、例えばので。

+0

ありがとうございました。私はいくつかの間違いを犯しました。 。あなたの紳士と女性は素晴らしいです。ありがとうございました。 – Vuken