import random
import time
def car_game():
print("\nWelcome to the Car Game!")
print("Race your car to the finish line!")
time.sleep(1)
race_distance = 100
player_position = 0
while player_position < race_distance:
input("Press Enter to accelerate...")
player_position += random.randint(1, 10)
print(f"Your car is at position {player_position} / {race_distance}")
time.sleep(0.5)
print("You crossed the finish line! You win!\n")
def number_guessing_game():
print("\nWelcome to the Number Guessing Game!")
print("Guess the number between 1 and 100.")
number_to_guess = random.randint(1, 100)
attempts = 0
while True:
guess = int(input("Enter your guess: "))
attempts += 1
if guess < number_to_guess:
print("Too low! Try again.")
elif guess > number_to_guess:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number in {attempts} attempts.")
break
print("Game Over!\n")
def word_guessing_game():
print("\nWelcome to the Word Guessing Game!")
word_list = ["python", "developer", "keyboard", "laptop", "programming"]
word_to_guess = random.choice(word_list)
guessed_word = ["_"] * len(word_to_guess)
attempts = 6
while attempts > 0 and "_" in guessed_word:
print(f"Word: {' '.join(guessed_word)}")
letter = input("Guess a letter: ").lower()
if letter in word_to_guess:
for i in range(len(word_to_guess)):
if word_to_guess[i] == letter:
guessed_word[i] = letter
print("Correct!")
else:
attempts -= 1
print(f"Wrong! You have {attempts} attempts left.")
print()
if "_" not in guessed_word:
print(f"Congratulations! You guessed the word: {''.join(guessed_word)}\n")
else:
print(f"Game Over! The word was: {word_to_guess}\n")
def main_menu():
while True:
print("Welcome to the Random Mini-Games Collection!")
print("Choose a game to play:")
print("1. Car Game")
print("2. Number Guessing Game")
print("3. Word Guessing Game")
print("4. Exit")
choice = input("Enter the number of your choice: ")
if choice == "1":
car_game()
elif choice == "2":
number_guessing_game()
elif choice == "3":
word_guessing_game()
elif choice == "4":
print("Thanks for playing! Goodbye!")
break
else:
print("Invalid choice! Please select a valid option.")
if __name__ == "__main__":
main_menu()