🎮 Game 11: Math Quiz (Random Equations)

 

🎮 Game 11: Math Quiz (Random Equations)

python
import random def math_quiz(): score = 0 for _ in range(5): a = random.randint(1, 10) b = random.randint(1, 10) op = random.choice(['+', '-', '*']) expression = f"{a} {op} {b}" answer = eval(expression) user_answer = input(f"What is {expression}? ") if user_answer.isdigit() and int(user_answer) == answer: print("Correct!") score += 1 else: print(f"Wrong! The answer was {answer}") print(f"Final Score: {score}/5") math_quiz()

🎮 Game 12: Even or Odd Game

python
def even_or_odd(): import random while True: number = random.randint(1, 100) guess = input(f"Is {number} even or odd? (even/odd): ").strip().lower() if (number % 2 == 0 and guess == "even") or (number % 2 == 1 and guess == "odd"): print("Correct!") else: print("Wrong!") if input("Play again? (y/n): ").lower() != 'y': break even_or_odd()

🎮 Game 13: Word Scramble

python
import random def word_scramble(): words = ["python", "keyboard", "developer", "program", "function"] word = random.choice(words) scrambled = ''.join(random.sample(word, len(word))) print(f"Unscramble the word: {scrambled}") guess = input("Your guess: ") if guess.lower() == word: print("Correct!") else: print(f"Wrong! The word was {word}") word_scramble()

🎮 Game 14: Memory Match (Console)

python
import random import time def memory_game(): print("Memorize the numbers!") numbers = [random.randint(10, 99) for _ in range(5)] print("Numbers:", numbers) time.sleep(3) print("\n" * 50) # Clear screen hack for i in range(5): guess = input(f"What was number #{i+1}? ") if not guess.isdigit() or int(guess) != numbers[i]: print("Wrong! Game over.") return print("You remembered all numbers! Well done.") memory_game()

🎮 Game 15: Catch the Falling Object (Pygame)

python
import pygame import random pygame.init() win = pygame.display.set_mode((500, 500)) pygame.display.set_caption("Catch the Falling Object") player = pygame.Rect(200, 450, 60, 10) object_rect = pygame.Rect(random.randint(0, 440), 0, 20, 20) speed = 5 clock = pygame.time.Clock() score = 0 font = pygame.font.SysFont(None, 36) running = True while running: win.fill((0, 0, 0)) pygame.draw.rect(win, (0, 255, 0), player) pygame.draw.rect(win, (255, 0, 0), object_rect) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player.left > 0: player.x -= 7 if keys[pygame.K_RIGHT] and player.right < 500: player.x += 7 object_rect.y += speed if object_rect.colliderect(player): score += 1 object_rect.y = 0 object_rect.x = random.randint(0, 440) elif object_rect.y > 500: print("Game Over! Final Score:", score) running = False text = font.render(f"Score: {score}", True, (255, 255, 255)) win.blit(text, (10, 10)) pygame.display.flip() clock.tick(60) pygame.quit()

Comments