From c731cd335fb969e9dae3b1c6a8ef967c0ddceae6 Mon Sep 17 00:00:00 2001 From: "artem.korotenko" Date: Tue, 22 Nov 2022 00:37:21 +0200 Subject: [PATCH 1/4] updated validation --- main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.py b/main.py index 83d588c..cb60193 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,18 @@ 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 @@ -26,6 +38,10 @@ def is_game_over(): while not is_game_over(): guess = input("Your next take: ") + + if not guess_is_valid(guess): + continue + if guess in full_list: guessed += 1 if guessed == WORDS_TO_WIN: From af82ca5ab70f295f141d3807231526a7a4160ea0 Mon Sep 17 00:00:00 2001 From: "artem.korotenko" Date: Tue, 22 Nov 2022 00:38:52 +0200 Subject: [PATCH 2/4] fancy message --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 83d588c..c8036b2 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,9 @@ def congratulate_user(): - print("You win!") + print("=============================") + print("= Congratulations! You won! =") + print("=============================") def is_game_over(): From e62173d0a4ff69f8bf813c88d1a51388da46c672 Mon Sep 17 00:00:00 2001 From: dburdak Date: Thu, 31 Oct 2024 00:00:45 +0200 Subject: [PATCH 3/4] Added validation for repeated words --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 94b82e3..83ed884 100644 --- a/main.py +++ b/main.py @@ -40,10 +40,12 @@ def guess_is_valid(candidate): 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 From ce9fa54d34dae635be5781f4a2af77c9f04800fd Mon Sep 17 00:00:00 2001 From: dburdak Date: Thu, 31 Oct 2024 00:13:06 +0200 Subject: [PATCH 4/4] Added individual message of lost --- main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 83ed884..8ee456e 100644 --- a/main.py +++ b/main.py @@ -58,4 +58,7 @@ def guess_is_valid(candidate): 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")