123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- from os import system
- word_list = ["monkey", "mouse", "camel"]
- #TODO-1 - Randomly choose a word from the word_list and assign it to a variable called chosen_word.
- #TODO-2 - Ask the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase.
- #TODO-3 - Check if the letter the user guessed (guess) is one of the letters in the chosen_word.
- import random
- game_word = random.choice(word_list)
- display = []
- for i in range(len(game_word)):
- display.append("_")
- def print_result():
- result = "||" + "||".join(display) + "||"
- print(result)
- def change_display(positions):
- if len(positions) > 0:
- for pos in positions:
- display[pos] = game_word[pos]
- life_counter = 6
- def print_ascii_art():
- stages = ['''
- +---+
- | |
- O |
- /|\ |
- / \ |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- / |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /| |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- | |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- |
- |
- |
- =========
- ''', '''
- +---+
- | |
- |
- |
- |
- |
- =========
- ''']
- print(stages[life_counter])
- def check_letter(letter):
- right_letters = []
- for n in range(len(game_word)):
- if game_word[n] == letter:
- right_letters.append(n)
- return right_letters
- def check_word():
- is_complete = True
- if "_" in display:
- is_complete = False
- return is_complete
- inputed_letters = []
- system('clear')
- print_result()
- while True:
- guess = input("Guess a letter: ").lower()
- system('clear')
- if guess not in inputed_letters:
- inputed_letters.append(guess)
- results = check_letter(guess)
- if len(results) > 0:
- change_display(results)
- print("Yes takaya bukva")
- else:
- life_counter -= 1
- print("No matches")
- else:
- print("This letter already opened. Try another one")
- print_result()
- print_ascii_art()
- if check_word():
- print("You are win!")
- break
- if life_counter < 1:
- print("You are dead")
- break
|