【发布时间】:2022-12-06 11:59:52
【问题描述】:
它在每次猜测后打印单词,而不是在 6 次猜测结束后将其提供给他们
我尝试设置 attempts = 6,如果这个词在我的 json 文件中的单词列表中,它会从尝试中减去一个,如果猜测的单词不在 json 文件中,它不会从尝试中减去,如果尝试达到零它会跳出循环并告诉他们
import json
import random
black = '\033[40m'
green = '\033[42m'
yellow = '\033[43m'
f = open('wordle_no_dupes.json')
info = json.load(f)
f.close
word = random.choice(info)
print("Enter a 5 letter word: ")
attempts = 6
for attempt in range(1, 7):
guess = (input("Enter Guess: ").lower())
if guess in info:
attempts = attempts - 1
if guess not in info:
attempts = attempts - 0
if attempts == 0:
break
print("The word was", word)
for i in range(5):
if guess[i] == word[i]:
print(green, guess[i] , end = "")
elif guess[i] in word:
print(yellow, guess[i] , end = "")
else:
print(black, guess[i] , end = "")
if guess == word:
break
print("You got it!!")
【问题讨论】:
标签: python