forked from aishaji123/oneliners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.py
2 lines (1 loc) · 1.43 KB
/
hangman.py
1
hangman = [exec("import random"),(wordlist := 'ant baboon badger bat bear beaver camel cat clam cobra cougar coyote crow deer dog donkey duck eagle ferret fox frog goat goose hawk lion lizard llama mole monkey moose mouse mule newt otter owl panda parrot pigeon python rabbit ram rat raven rhino salmon seal shark sheep skunk sloth snake spider stork swan tiger toad trout turkey turtle weasel whale wolf wombat zebra'.split()),(word := random.choice(wordlist)),(unguessed := set(word) - set(list("aeiou"))),(misses := set(list("aeiou"))),(checkState := lambda: [+1,print("You win!")][0] if len(unguessed)==0 else [-1,print("You lose!")] if len(misses)==12 else [0][0]),(checkGuess := lambda: [[[unguessed.remove(guess),print("Correct!",guess, "is a letter in the word")] if guess in unguessed else [[misses.add(guess),print( f"\nYou now have {12-len(misses)} guesses remaining\nYou already guessed {''.join(i for i in misses if i not in ['a','e','i','o','u'])}")] if guess not in word else print(f"You already guessed {guess}")]] if (guess not in misses and len(guess)==1) else [print("Invalid Guess :("),checkGuess()] for guess in [input("\nGuess a letter: ")]]),(displayWord := lambda: print("".join(str(i)+" " if i not in unguessed else "__ " for i in word ))),(playGame := lambda :[print("\n\n"),displayWord(),checkGuess(),print("\n\n"),playGame() if checkState()==0 else [print("\n\n"),print("The word was","".join(i for i in word))],"!\n\n" ]),playGame()]