Skip to main content

🎮 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

Popular posts from this blog

Teacher Index – Teaching Jobs & Terms and Conditions in Nepal

Teacher Index – Terms & Conditions | K-Learning • The Jump Academy • Focus Edge Official Policy Teacher Index – Terms & Conditions Transparent engagement for teaching opportunities across Nepal with K-Learning , The Jump Academy , and Focus Edge Tuition Classes . Last updated: Scope: Grades 1–12, College & University • Institutional • Home Tuition • Online Contents 1. Introduction 2. Eligibility 3. Engagement Structure 4. Fees & Payment Terms 5. Teacher Responsibilities 6. Institutional Responsibilities 7. Termination & Suspension 8. Confidentiality & Data Protection 9. Disclaimer 10. Governing Law 11. Declaration & Acknowledgement Apply ...

PASHUPATI PROPERTIES - A REAL ESTATE COMPANY

🏡 Pashupati Properties – Your Trusted Real Estate Partner! 🏡 Looking to buy,sell, or invest in properties? Pashupati Properties is a renowned real estate company, helping you find the perfect property in Kathmandu, Bhaktapur, Lalitpur, Dhading, Chitwan, Pokhara, and Narayanghat. 📌 Fast Transactions: We work within 7 to 10 days to complete deals. 💸 Commission: We charge only 7% of the total traded amount. 📍 Located at New Baneshwor, Kathmandu 📞 Call/Message/WhatsApp: 9701322765 🌐 Website: https://empiricalten.blogspot.com/2025/02/pashupati-properties-realestate-company.html Whether you're searching for your dream home, commercial space, or investment opportunities, we are here to guide you with expert advice and reliable service. Let’s build your future together! 🏠✨ #RealEstate #PashupatiProperties #Kathmandu #Bhaktapur #Lalitpur #Dhading #Chitwan #Pokhara #Narayanghat #DreamHome #Investment #PropertyForSale #BuySellRent #NewBaneshwor #HouseH...

Grade 12 Accounts MCQ Quiz | Final Accounts, Worksheet & Cost Sheet Practice (With Answers & Explanations)

Grade 12 Accounts MCQ Quiz | Final Accounts • Worksheet • Cost Sheet Grade 12 Accounts MCQ Quiz Final Accounts • Worksheet • Cost Sheet All topics Final Accounts Worksheet Cost Sheet Shuffle Reset Submit Tap an option to check your answer instantly. Explanations appear after you choose. Use Shuffle to practice and Submit to see totals. 0 / 0 answered Score: 0% Topic: All