day7_Udemy Python 100days

import random

import day7_hangman_words

chosen_word = random.choice(day7_hangman_words.word_list)
word_length = len(chosen_word)
#from day7_hangman_words import word_list
#chosen_word = random.choice(word_list)

lives = 6
end_of_game = False

from day7_hangman_art import logo,stages
print(logo)

#Testing code
#print(f"Pssst,the solution is {chosen_word}")

#Create blanks
display = []
for _ in range(word_length):
    display += "_"

while not end_of_game:
    guess = input("Guess a letter:").lower()

    if guess in display:
        print(f"You've already guessed {guess}")

    #Check guessed letter
    for position in range(word_length):
        letter = chosen_word[position]
        if letter == guess:
            display[position] = letter

    if guess not in chosen_word:
        lives -= 1
        print(f"You guessed {guess},that's not in the word.You lose a life.")
        if lives == 0:
            end_of_game = True
            print("You lose.")

    #Join all the elements in the list and turn it into a String
    print(f"{' '.join(display)}" )

    if "_" not in display:
        end_of_game = True
        print("You win.")

    print(stages[lives])


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值