猫史档案馆


【Python作品分享】单词九连猜【作品秀】

用户:LC_COOLCITY___QwQLC_COOLCITY___QwQ查看:0 回复:0 评论:0 创建时间:2022-08-02T10:48:33


【作品展示】

center_image

 

【作品介绍】

 

【作品源代码】

import random

lives = 9
words = ['pizza', 'fairy', 'teeth', 'shirt', 'otter', 'plane']
secret_word = random.choice(words)
clue = list('?????')
heart_symbol = u'\u27喵'
gueesed_word_correctly = False


def update_clue(gueesed_letter, secret_word, clue):
    index = 0
    while index < len(secret_word):
        if gueesed_letter == secret_word[index]:
            clue[index] = gueesed_letter
    index = index+1


while lives > 0:
    print(clue)
    print('生命值剩余:'+heart_symbol*lives)
    guees = str(input('猜字母或整个单词:'))

    if guees == secret_word:
        gueesed_word_correctly = True
        break
    if guees in secret_word:
        update_clue(guees, secret_word, clue)
    else:
        print('错了,你丢失了一条生命')
        lives = lives-1
if gueesed_word_correctly:
    print('你赢了,单词是' + secret_word)
else:
    print('你输了,单词是' + secret_word)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页