enhance this code and give beat the shark game mode option: import random print("Welcome…
- User
enhance this code and give beat the shark game mode option: import random
print("Welcome to my pyword guessing game..") def guess_the_word(): # Word lists for different difficulty levels words = { "easy": ["code", "java", "data", "chip", "byte"], "medium": ["python", "script", "binary", "server", "backup"], "hard": ["software", "hardware", "database", "compiler", "protocol"] }
code# This asks the player to select a difficulty level difficulty = input("Choose a difficulty (Easy, Medium, Hard): ").strip().lower() while difficulty not in words: print("Invalid choice! Please select Easy, Medium, or Hard.") difficulty = input("Choose a difficulty (Easy, Medium, Hard): ").strip().lower() # Select a random word from the chosen difficulty level secret_word = random.choice(words[difficulty]) # Initialize guessed word display and tracking variables guessed_word = ["_"] * len(secret_word) guessed_letters = [] attempts = 10 # Number of attempts remains constant across difficulties print(f"\nLet's play Guess the Word! Difficulty: {difficulty.capitalize()}") print(" ".join(guessed_word)) # Main game loop while attempts > 0 and guessed_word != list(secret_word): print("\nGuessed letters:", " ".join(guessed_letters)) guess = input("Guess a letter: ").lower() # If the player guesses more than one letter, if not guess.isalpha() or len(guess) != 1: print("Please enter a single letter.") continue # Check if the letter was already guessed if guess in guessed_letters: print("You already guessed this letter.") continue # Add letter to guessed list guessed_letters.append(guess) # Check if letter is in the word if guess in secret_word: for index, letter in enumerate(secret_word): if letter == guess: guessed_word[index] = letter print("Good guess!") else: attempts -= 1 print(f"That letter is not in the word. You have {attempts} attempts left.") # Display current progress print(" ".join(guessed_word)) # Endgame messages if guessed_word == list(secret_word): print("\n🎉 Congratulations! You guessed the word correctly! 🎉") else: print(f"\n❌ Unlucky! The word was '{secret_word}'. Better luck next time!") - Assistant
- User
Make a typewriter effect on the first prints
- Assistant