diff --git a/main.py b/main.py index 99603fd..8ee456e 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,28 @@ def congratulate_user(): - print(f"Congratulations, you won! your words: {guesses}") + print("=============================") + print("= Congratulations! You won! =") + print("=============================") + print(f"Your words: {guesses}") def is_game_over(): return guessed == WORDS_TO_WIN or errors == ERRORS_TO_LOSE +def guess_is_valid(candidate): + for letter in candidate: + if letter not in word: + print(f"You can not use letter {letter}") + return False + count = word.count(letter) + if count < candidate.count(letter): + print(f"You can use letter {letter} only {count} times") + return False + return True + + guessed = 0 errors = 0 @@ -25,9 +40,15 @@ def is_game_over(): print(f"Can you make up {WORDS_TO_WIN} words from letters in word provided by me?") print(f"Your word is '{word}'") - +already=[] while not is_game_over(): guess = input("Your next take: ") + while guess in already: + guess = input("This word already entered, try another: ") + already.append(guess) + if not guess_is_valid(guess): + continue + if guess in full_list: guessed += 1 guesses.append(guess) @@ -37,4 +58,7 @@ def is_game_over(): print(f"That's right! {WORDS_TO_WIN - guessed} to go") else: errors += 1 - print(f"Oops :( No such word, you have {ERRORS_TO_LOSE - errors} lives more") + if errors==3: + print("Sorry you have no lives, you lost") + else: + print(f"Oops :( No such word, you have {ERRORS_TO_LOSE - errors} lives more")