import random
words = [‘desk’,‘seats’,‘windows’,‘factory’,‘area’]
secret_word = random.choice(words)
#print(secret_word)
sayyes=False
l=list(‘???’)
lives = 3
heart = u’\u2764’
def updateword(guess_word,secret_word,l):
i=0
while i<len(secret_word):
if guess_word == secret_word[i]:
l[i]=guess_word
i+=1
while lives >0:
print(‘欢迎来到单词游戏’)
print(l)
print(‘你的剩余生命:’,heart*lives)
guess_word=input(‘请输入你猜测的单词或字母:’)
print(guess_word)
if guess_word == secret_word:
sayyes=True
break
if guess_word in secret_word:
updateword(guess_word,secret_word,l)
else:
print(‘你错了丢了 一条命’)
lives=lives-1
if sayyes:
print(‘恭喜你猜对了,你赢了,秘密单词是:’,secret_word)
else:
print(‘你错了,秘密单词是:’,secret_word)
Python玩个小游戏 猜单词
最新推荐文章于 2024-07-12 16:16:27 发布