Skip to content

Commit 7b240c7

Browse files
authored
Merge branch 'main' into fix-simon-says-visibility
2 parents 2170e1c + 11c3368 commit 7b240c7

44 files changed

Lines changed: 7746 additions & 1930 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 98 additions & 22 deletions
Large diffs are not rendered by default.

games/Blackjack-21/Blackjack-21.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import random
2+
3+
deck = [
4+
"A♠️", "2♠️", "3♠️", "4♠️", "5♠️", "6♠️", "7♠️", "8♠️", "9♠️", "10♠️", "J♠️", "Q♠️", "K♠️",
5+
6+
"A♥️", "2♥️", "3♥️", "4♥️", "5♥️", "6♥️", "7♥️", "8♥️", "9♥️", "10♥️", "J♥️", "Q♥️", "K♥️",
7+
8+
"A♦️", "2♦️", "3♦️", "4♦️", "5♦️", "6♦️", "7♦️", "8♦️", "9♦️", "10♦️", "J♦️", "Q♦️", "K♦️",
9+
10+
"A♣️", "2♣️", "3♣️", "4♣️", "5♣️", "6♣️", "7♣️", "8♣️", "9♣️", "10♣️", "J♣️", "Q♣️", "K♣️"
11+
]
12+
13+
random.shuffle(deck)
14+
15+
player_hand = []
16+
dealer_hand = []
17+
18+
player_cards = []
19+
dealer_cards = []
20+
21+
22+
def calculate(hand):
23+
count = 0
24+
aces = 0
25+
for value in hand:
26+
count += value
27+
if value == 1:
28+
aces += 1
29+
30+
while aces > 0 and count + 10 <= 21:
31+
count += 10
32+
aces -= 1
33+
34+
return count
35+
36+
def check(rank):
37+
if rank in ['Q','K','J']:
38+
return 10
39+
elif rank == 'A':
40+
return 1
41+
else:
42+
return int(rank)
43+
44+
def player_draws():
45+
card = deck.pop() # take a card from deck
46+
47+
player_cards.append(card)
48+
49+
rank = card[:-2] # extract Rank
50+
51+
rank = check(rank) # validate the rank into numbers
52+
53+
player_hand.append(rank)
54+
55+
56+
57+
def dealer_draws():
58+
card = deck.pop()
59+
60+
dealer_cards.append(card)
61+
62+
rank = card[:-2]
63+
64+
rank = check(rank)
65+
66+
dealer_hand.append(rank)
67+
68+
69+
player_draws()
70+
dealer_draws()
71+
72+
player_draws()
73+
dealer_draws()
74+
75+
76+
player_count = calculate(player_hand)
77+
dealer_count = calculate(dealer_hand)
78+
79+
80+
player_turn = True
81+
82+
while player_turn:
83+
84+
choice = input("hit or Stand: ").lower()
85+
86+
match choice:
87+
case "hit":
88+
player_draws()
89+
player_count = calculate(player_hand)
90+
91+
print("player cards", player_cards)
92+
print("player_count", player_count)
93+
94+
if player_count > 21:
95+
print("Bust! player lose!")
96+
player_turn = False
97+
exit()
98+
99+
case "stand":
100+
player_count = calculate(player_hand)
101+
102+
print("player cards", player_cards)
103+
print("player_count", player_count)
104+
print("player stands...")
105+
break
106+
107+
108+
while dealer_count < 17:
109+
dealer_draws()
110+
111+
dealer_count = calculate(dealer_hand)
112+
113+
114+
# final result
115+
116+
if dealer_count > 21:
117+
print("dealer Bust! player wins!")
118+
elif player_count == dealer_count:
119+
print("draw!")
120+
elif player_count > dealer_count:
121+
print("player wins!")
122+
else:
123+
print("dealer wins!")
124+
125+
print("dealer cards", dealer_cards)
126+
print("player cards", player_cards)
127+
128+
129+
print("dealer_count", dealer_count, " \n player_count", player_count)
130+
131+

games/Hangman-Game/Hangman-Game.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,71 @@
44
print("WELCOME TO HANGMAN GAME")
55
print("=" * 50)
66

7-
words = ['python', 'programming', 'computer', 'algorithm', 'keyboard',
8-
'monitor', 'software', 'hardware', 'database', 'network',
9-
'internet', 'developer', 'variable', 'function', 'application']
7+
word_data = [
8+
{"word": "python", "hint": "Programming language 🐍"},
9+
{"word": "java", "hint": "Popular object-oriented programming language"},
10+
{"word": "computer", "hint": "Electronic machine that processes data"},
11+
{"word": "keyboard", "hint": "Used to type input ⌨️"},
12+
{"word": "monitor", "hint": "Displays output on screen 🖥️"},
13+
{"word": "mouse", "hint": "Pointing device 🖱️"},
14+
{"word": "internet", "hint": "Global network 🌐"},
15+
{"word": "network", "hint": "Connected computers"},
16+
{"word": "database", "hint": "Stores structured data"},
17+
{"word": "algorithm", "hint": "Step-by-step problem-solving method"},
18+
19+
{"word": "tiger", "hint": "Animal 🐾 with stripes"},
20+
{"word": "elephant", "hint": "Largest land animal"},
21+
{"word": "giraffe", "hint": "Tall animal with long neck"},
22+
{"word": "lion", "hint": "King of jungle"},
23+
{"word": "zebra", "hint": "Black and white striped animal"},
24+
25+
{"word": "apple", "hint": "Fruit 🍎 keeps doctor away"},
26+
{"word": "banana", "hint": "Yellow fruit 🍌"},
27+
{"word": "mango", "hint": "King of fruits 🥭"},
28+
{"word": "grapes", "hint": "Small round fruit 🍇"},
29+
{"word": "orange", "hint": "Citrus fruit 🍊"},
30+
31+
{"word": "india", "hint": "Country 🇮🇳 in South Asia"},
32+
{"word": "china", "hint": "Most populated country"},
33+
{"word": "brazil", "hint": "Country famous for Amazon rainforest"},
34+
{"word": "canada", "hint": "Country with maple leaf 🍁"},
35+
{"word": "japan", "hint": "Land of rising sun 🌅"},
36+
37+
{"word": "school", "hint": "Place to study 📚"},
38+
{"word": "teacher", "hint": "Person who teaches"},
39+
{"word": "student", "hint": "Person who learns"},
40+
{"word": "library", "hint": "Place with books"},
41+
{"word": "college", "hint": "Higher education institute"},
42+
43+
{"word": "football", "hint": "Sport ⚽ played worldwide"},
44+
{"word": "cricket", "hint": "Popular sport in India 🏏"},
45+
{"word": "tennis", "hint": "Played with racket 🎾"},
46+
{"word": "hockey", "hint": "India's national sport"},
47+
{"word": "badminton", "hint": "Played with shuttlecock"},
48+
49+
{"word": "doctor", "hint": "Treats patients 🩺"},
50+
{"word": "engineer", "hint": "Builds and designs systems"},
51+
{"word": "artist", "hint": "Creates paintings 🎨"},
52+
{"word": "lawyer", "hint": "Works with law ⚖️"},
53+
{"word": "chef", "hint": "Cooks food 👨‍🍳"},
54+
55+
{"word": "mobile", "hint": "Used for calling 📱"},
56+
{"word": "laptop", "hint": "Portable computer 💻"},
57+
{"word": "camera", "hint": "Used to take photos 📷"},
58+
{"word": "speaker", "hint": "Outputs sound 🔊"},
59+
{"word": "battery", "hint": "Stores power 🔋"},
60+
61+
{"word": "rain", "hint": "Water falling from sky 🌧️"},
62+
{"word": "summer", "hint": "Hot season ☀️"},
63+
{"word": "winter", "hint": "Cold season ❄️"},
64+
{"word": "cloud", "hint": "White thing in sky ☁️"},
65+
{"word": "storm", "hint": "Strong wind and rain"}
66+
]
67+
68+
selected = random.choice(word_data)
69+
word = selected["word"]
70+
hint = selected["hint"]
1071

11-
word = random.choice(words)
1272
word_length = len(word)
1373

1474
guessed_letters = []
@@ -18,6 +78,7 @@
1878
won = False
1979

2080
print(f"\nThe word has {word_length} letters.")
81+
print(f"Hint: {hint}")
2182
print(f"You have {max_attempts} attempts to guess the word.\n")
2283

2384
while attempts < max_attempts and not won:

games/Math-Quiz/Math-Quiz.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@
99
import json
1010
import os
1111
import time
12-
import winsound
12+
try:
13+
import winsound
14+
except ImportError:
15+
winsound = None
1316

1417
# ─────────────────────────────────────────────
1518
# Utility Functions
1619
# ─────────────────────────────────────────────
1720

1821
def play_sound(sound_type):
22+
if not winsound:
23+
try:
24+
if hasattr(tk, '_default_root') and tk._default_root:
25+
tk._default_root.bell()
26+
else:
27+
print('\a', end='', flush=True)
28+
except Exception:
29+
pass
30+
return
1931
try:
2032
if sound_type == 'correct':
2133
winsound.Beep(1000, 150) # Frequency, duration
File renamed without changes.

games/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ This folder contains beginner-friendly Python mini games. Each game is self-cont
88
- Dots-Boxes-AI
99
- Emoji-Memory-Game
1010
- FLAMES-Game
11-
- Flipping-toss
11+
- Flipping-Toss
1212
- Hangman-Game
1313
- Number-Guessing-Game
14-
- Number-Sliding_puzzle
14+
- Number-Sliding-Puzzle
1515
- Password-Forge
1616
- Reverse-Hangman-Game
1717
- Rock-Paper-Scissor
18-
- Roling-Dice
18+
- Rolling-Dice
1919
- Simon-Says
2020
- Snake-Game
2121
- Tic-Tac-Toe
Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
1-
import random
1+
class Rock_Paper_Scissor:
2+
def __init__(self):
3+
self.user_score = 0
4+
self.computer_score = 0
5+
self.rounds_played = 0
6+
self.play_game()
27

8+
def users_play(self):
9+
import random
10+
choices = ["rock", "paper", "scissor"]
11+
12+
user_choice = ""
13+
while user_choice not in choices:
14+
user_choice = input("Enter your choice (rock, paper, or scissor): ").lower()
15+
if user_choice not in choices:
16+
print("Invalid choice. Please choose rock, paper, or scissor.")
317

4-
print("🎮 Rock, Paper, Scissors Game! 🎮")
5-
print("🪨 Rock beats ✂️ Scissors")
6-
print("📄 Paper beats 🪨 Rock")
7-
print("✂️ Scissors beats 📄 Paper\n")
18+
computer_choice = random.choice(choices)
19+
print(f"Computer chose: {computer_choice}")
820

9-
Flag = True
21+
if user_choice == computer_choice:
22+
print("It's a Tie!")
23+
return "tie"
24+
elif (user_choice == "rock" and computer_choice == "scissor") or \
25+
(user_choice == "paper" and computer_choice == "rock") or \
26+
(user_choice == "scissor" and computer_choice == "paper"):
27+
print("You Win this round!")
28+
return "user"
29+
else:
30+
print("Computer Wins this round!")
31+
return "computer"
1032

11-
valid = {
12-
'r': 1,
13-
'p': 2,
14-
's': 3,
15-
}
1633

17-
key = {
18-
1: 'Rock 🪨',
19-
2: 'Paper 📄',
20-
3: 'Scissors ✂️',
21-
}
34+
def statistics(self):
35+
print("\n--- Game Statistics ---")
36+
print(f"Rounds Played: {self.rounds_played}")
37+
print(f"Your Score: {self.user_score}")
38+
print(f"Computer Score: {self.computer_score}")
2239

2340

24-
while Flag:
25-
value = str(input('🎯 Choose - Rock(r), Paper(p), Scissors(s): ')).lower()
26-
computer = random.randint(1, 3)
41+
def save_game(self):
42+
name = input("Enter your name to save the results (optional): ")
43+
if not name:
44+
name = "Anonymous"
45+
result_string = f"Player: {name}, Final Score: {self.user_score} - {self.computer_score} (User-Computer), Rounds: {self.rounds_played}\n"
46+
try:
47+
with open("game_results.txt", "a") as f:
48+
f.write(result_string)
49+
print("Game results saved successfully.")
50+
except IOError:
51+
print("Error: Could not save game results to file.")
2752

28-
if value not in valid:
29-
print('❌ Invalid choice! Please enter r, p, or s. Try again.\n')
30-
continue
3153

32-
print(f'\n👤 You chose: {key[valid[value]]}')
33-
print(f'🤖 Computer chose: {key[computer]}\n')
54+
def play_game(self):
55+
print("Welcome to Rock, Paper, Scissors!")
56+
while True:
57+
self.rounds_played += 1
58+
print(f"\n--- Round {self.rounds_played} ---")
59+
60+
round_winner = self.users_play() # Call the users_play method for one round
3461

35-
if (valid[value] == 1 and computer == 2) or (valid[value] == 2 and computer == 3) or (valid[value] == 3 and computer == 1):
36-
print('😢 You lost!! Better luck next time!\n')
37-
elif valid[value] == computer:
38-
print("🤝 It's a Tie!! Great minds think alike!\n")
39-
else:
40-
print('🎉 You won!! Congratulations!\n')
62+
if round_winner == "user":
63+
self.user_score += 1
64+
elif round_winner == "computer":
65+
self.computer_score += 1
4166

42-
response = str(input('Continue playing? Yes(y) or No(n): ')).lower()
43-
44-
if response == 'y':
45-
Flag = True
46-
print()
47-
else:
48-
Flag = False
49-
print('\n👋 Thanks for playing! See you next time!\n')
67+
self.statistics()
68+
play_again_input = input("do you want to play again ? (yes/no): ").lower()
69+
if play_again_input != "yes":
70+
print("\nThanks for playing! Final results:")
71+
self.statistics()
72+
self.save_game()
73+
break
74+
75+
game = Rock_Paper_Scissor()
76+
print(game)

0 commit comments

Comments
 (0)