Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 commits/ updated validation and new congratulation message #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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")