私はクラスのための簡単なハングマンゲームを作っています。現在のプログラムは、たとえユーザーが正しい答えを得たとしても、図面のすべてのステップを実行します。なぜelseが正しく動作しないのですか?
import turtle
import random
import sys
while True:
list = ['report', 'beach', 'mayor', 'score', 'overeat', 'load', 'battery', 'social', 'honor', 'risk']
turns = 10
guesses = ''
err = 0
usedw = random.choice(list)
wn = turtle.Screen()
draw = turtle.Turtle()
length = len(usedw)
print("Welcome to hangman your word is", length, "letters long.")
while turns > 0:
guess = input("Choose a character: ")
guesses += guess;
lengthr = 0
for char in usedw:
if char in guesses:
print (char,)
lengthr += 1;
else:
err += 1;
if err == 1:
draw.goto(0,0)
draw.down()
draw.goto(200,0)
elif err == 2:
draw.up()
draw.goto(0,0)
draw.down()
draw.goto(0,200)
elif err == 3:
draw.up()
draw.goto(0,200)
draw.down()
draw.goto(100,200)
elif err == 4:
draw.up()
draw.goto(100,200)
draw.down()
draw.goto(100,150)
elif err == 5:
draw.up()
draw.goto(100,100)
draw.down()
draw.circle(25)
elif err == 6:
draw.up()
draw.goto(100,100)
draw.down()
draw.goto(100,50)
elif err == 7:
draw.up()
draw.goto(75,90)
draw.down()
draw.goto(125,90)
elif err == 8:
draw.up()
draw.goto(100,50)
draw.down()
draw.goto(75,35)
elif err == 9:
draw.up()
draw.goto(100,50)
draw.down()
draw.goto(125,35)
print("You loose.")
break
if lengthr == length:
print ("You won!")
break
cont = input("Would you like to continue (y/n) ")
if cont == 'y':
print("Alright!")
else:
print("Thanks for playing!")
break
sys.exit()
あなたが推測していなかったキャラクターごとに1度詠唱しています。 – user2357112