「独学プログラマー」で勉強中です。
下記コードで、【if "_" not in board:】に invalid syntax エラーが出ます
インデントを見直してもエラーとなってしまっています。
どこに問題があるのでしょうか。
def hangman(word): wrong=0 stages=["", "_____ ", "| ", "| | ", "| ", " 0 ", "| /|/ ", "| // ", "| ", ] rletters=list(word) board=["_"]*len(word) win=False print("Welcome to Hangman!") while wrong<len(stages)-1: print("\n") msg=("1文字を予想してね:") char=input(msg) if char in rletters: cind =rletters.index(char) board[cind]=char rletters[cind]="$" else: wrong +=1 print(" ".join(board)) e=wrong +1 print("\n".join(stages[0:e]) if "_" not in board: print("You WIN!") print(" ".join(board)) win=True break if not win: print("\n".join(stages[0:wrong+1])) print("You LOSE...The Answer is {}.".format(word)) hangman("cat")
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/07 13:54