2 回答
TA贡献1803条经验 获得超3个赞
稍微清理一下,就可以正常使用了!
import random
Words = ["Hades".upper(),"Zues".upper(), "pesidon".upper()]
Word_choosed = random.choice(Words)
Word_Choosed = list(Word_choosed)
a =[]
print(Word_Choosed)
for i in Word_choosed:
a += "_"
wrong = 0
correct = 0
while correct < 5:
print(''.join(a))
Incorrect = "yes"
Guess = str(input("Guess a letter?\n").upper())
for ltr in range(0, len(Word_choosed)):
if Guess == Word_choosed[ltr]:
a[ltr] = Guess
correct += 1
Incorrect = "no"
if Incorrect == "yes":
wrong += 1
print(f"wrong you have {5 - wrong } chances left")
if 5 - wrong == 0:
print("you lost")
break
elif a == Word_Choosed:
print("you won")
break
TA贡献1830条经验 获得超3个赞
您elif:在获胜和失败的代码中添加了一条语句。因此,python 只会执行一个 if 并且不会继续执行 elif 语句。你必须像这样修复你的代码:
import random
Words = ["Hades".upper(),"Zues".upper(), "pesidon".upper()]
Word_choosed = random.choice(Words)
Word_Choosed = list(Word_choosed)
a =[]
print(Word_Choosed)
for i in Word_choosed:
a += "_"
print(" ".join(a))
wrong = 0
while wrong < 5:
Incorrect = "yes"
Guess = str(input("Guess a letter?\n").upper())
for ltr in range(len(Word_choosed)):
if Guess == Word_choosed[ltr]:
a[ltr] = Guess
print(a)
wrong -= 1
Incorrect = "no"
if Guess != Word_choosed:
wrong += 1
if Incorrect == "yes":
print(f"wrong you have {5 - wrong } chances left")
if wrong == 5: # I changed this to if
print("you lost")
break # I added break you can remove it if you like
if list(a) == list(Word_Choosed): # changed this to if
print("you won")
break
添加回答
举报