🎮 Game 6: Hangman (Console)

 

🎮 Game 6: Hangman (Console)

python
import random def hangman(): words = ['python', 'hangman', 'developer', 'keyboard'] word = random.choice(words) guessed = "_" * len(word) tries = 6 guessed_letters = [] print("Hangman Game!") while tries > 0 and "_" in guessed: print("Word:", " ".join(guessed)) guess = input("Guess a letter: ").lower() if guess in guessed_letters: print("You already guessed that.") elif guess in word: guessed_letters.append(guess) guessed = "".join([c if c in guessed_letters else "_" for c in word]) else: tries -= 1 guessed_letters.append(guess) print(f"Wrong! Tries left: {tries}") if "_" not in guessed: print("You won! Word was:", word) else: print("You lost! Word was:", word) hangman()

🎮 Game 7: Coin Toss Simulator

python
import random def coin_toss(): while True: input("Press Enter to toss the coin...") result = random.choice(['Heads', 'Tails']) print("Result:", result) again = input("Toss again? (y/n): ") if again.lower() != 'y': break coin_toss()

🎮 Game 8: Dice Rolling Simulator

python
import random def roll_dice(): while True: input("Press Enter to roll the dice...") print("You rolled:", random.randint(1, 6)) again = input("Roll again? (y/n): ") if again.lower() != 'y': break roll_dice()

🎮 Game 9: Simple Quiz Game

python
def quiz(): questions = { "What is the capital of France? ": "paris", "What is 5 + 7? ": "12", "Who wrote 'Romeo and Juliet'? ": "shakespeare" } score = 0 for q, a in questions.items(): ans = input(q).lower() if ans == a: print("Correct!") score += 1 else: print("Wrong!") print(f"Your score: {score}/{len(questions)}") quiz()

🎮 Game 10: Pygame Paddle Bounce

python
import pygame pygame.init() win = pygame.display.set_mode((500, 400)) pygame.display.set_caption("Paddle Bounce") paddle = pygame.Rect(200, 350, 100, 10) ball = pygame.Rect(250, 200, 20, 20) ball_speed = [3, 3] clock = pygame.time.Clock() running = True while running: win.fill((0, 0, 0)) pygame.draw.rect(win, (0, 255, 0), paddle) pygame.draw.ellipse(win, (255, 0, 0), ball) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and paddle.left > 0: paddle.x -= 5 if keys[pygame.K_RIGHT] and paddle.right < 500: paddle.x += 5 ball.x += ball_speed[0] ball.y += ball_speed[1] if ball.left <= 0 or ball.right >= 500: ball_speed[0] *= -1 if ball.top <= 0: ball_speed[1] *= -1 if ball.colliderect(paddle): ball_speed[1] *= -1 if ball.bottom >= 400: print("Game Over") running = False pygame.display.flip() clock.tick(60) pygame.quit()

Comments