eduka projekti kirjeldus
import random as r
words_hard = [
"table", "star", "root", "flat", "turtle", "fish", "goat", "rocket",
"dragon", "power", "source", "program", "wheel", "candle", "dog", "cat", "branch"
]
words_easy = [
"dragonborn", "monosaccharide", "disposable", "environment",
"implementation", "disorientation", "carbohydrate", "disrespectful", "dominant"
]
difficulty = input("Please select difficulty('h' for 'hard' and 'e' for 'easy'): ")
if difficulty == 'h':
words = words_hard
elif difficulty == 'e':
words = words_easy
else:
raise ValueError("Not allowed input")
word = r.choice(words)
guesses = len(word)
guess_word = ["*"] * len(word)
while True:
print(f"\nGuesses left: {guesses}")
print(f"The word is: {''.join(guess_word)}")
char = input("Please enter single character: ")
if char in word:
for i in range(len(word)):
guess_word[i] = char if word[i] == char else guess_word[i]
else:
print(f"The character {char} is not in the word!")
guesses -= 1
if "".join(guess_word) == word:
print("\nYou won!")
print(f"The word is: {word}")
break
if guesses == 0:
print("\nYou lost!")
print(f"The word was {word}")
break