Skip to content

Commit a8acbd4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent d4bc1b0 commit a8acbd4

File tree

1 file changed

+141
-32
lines changed

1 file changed

+141
-32
lines changed

web_programming/Word-Scramble-Game.py

Lines changed: 141 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,132 @@
2323

2424
# Simple embedded word list (can be extended)
2525
WORD_LIST = [
26-
"planet", "python", "scramble", "library", "function", "variable",
27-
"keyboard", "monitor", "developer", "network", "package", "module",
28-
"algorithm", "debug", "database", "container", "virtual", "iterate",
29-
"compile", "syntax", "object", "inheritance", "interface", "performance",
30-
"encryption", "protocol", "bandwidth", "repository", "branch", "commit",
31-
"feature", "engine", "cursor", "iterator", "lambda", "generator",
32-
"concurrency", "thread", "process", "serializer", "message", "payload"
26+
"planet",
27+
"python",
28+
"scramble",
29+
"library",
30+
"function",
31+
"variable",
32+
"keyboard",
33+
"monitor",
34+
"developer",
35+
"network",
36+
"package",
37+
"module",
38+
"algorithm",
39+
"debug",
40+
"database",
41+
"container",
42+
"virtual",
43+
"iterate",
44+
"compile",
45+
"syntax",
46+
"object",
47+
"inheritance",
48+
"interface",
49+
"performance",
50+
"encryption",
51+
"protocol",
52+
"bandwidth",
53+
"repository",
54+
"branch",
55+
"commit",
56+
"feature",
57+
"engine",
58+
"cursor",
59+
"iterator",
60+
"lambda",
61+
"generator",
62+
"concurrency",
63+
"thread",
64+
"process",
65+
"serializer",
66+
"message",
67+
"payload",
3368
]
3469

3570
# Optional categories to make the game more interesting — each category is a small subset
3671
CATEGORIES = {
3772
"general": WORD_LIST,
38-
"programming": [w for w in WORD_LIST if w in (
39-
"python","function","variable","module","algorithm","debug","compile",
40-
"object","inheritance","interface","repository","commit","lambda","generator",
41-
"concurrency","thread","process"
42-
)],
43-
"networking": [w for w in WORD_LIST if w in (
44-
"network","protocol","bandwidth","packet" )],
73+
"programming": [
74+
w
75+
for w in WORD_LIST
76+
if w
77+
in (
78+
"python",
79+
"function",
80+
"variable",
81+
"module",
82+
"algorithm",
83+
"debug",
84+
"compile",
85+
"object",
86+
"inheritance",
87+
"interface",
88+
"repository",
89+
"commit",
90+
"lambda",
91+
"generator",
92+
"concurrency",
93+
"thread",
94+
"process",
95+
)
96+
],
97+
"networking": [
98+
w for w in WORD_LIST if w in ("network", "protocol", "bandwidth", "packet")
99+
],
45100
}
46101

47102
# New extended categories
48103
ANIMALS = [
49-
"elephant", "tiger", "penguin", "giraffe", "dolphin", "kangaroo", "alligator",
50-
"cheetah", "hedgehog", "raccoon", "squirrel", "porcupine", "butterfly", "octopus",
51-
"hummingbird", "flamingo"
104+
"elephant",
105+
"tiger",
106+
"penguin",
107+
"giraffe",
108+
"dolphin",
109+
"kangaroo",
110+
"alligator",
111+
"cheetah",
112+
"hedgehog",
113+
"raccoon",
114+
"squirrel",
115+
"porcupine",
116+
"butterfly",
117+
"octopus",
118+
"hummingbird",
119+
"flamingo",
52120
]
53121

54122
MOVIES = [
55-
"inception", "gladiator", "titanic", "avatar", "interstellar", "matrix", "casablanca",
56-
"goodfellas", "amadeus", "psycho", "rocky", "alien", "jaws"
123+
"inception",
124+
"gladiator",
125+
"titanic",
126+
"avatar",
127+
"interstellar",
128+
"matrix",
129+
"casablanca",
130+
"goodfellas",
131+
"amadeus",
132+
"psycho",
133+
"rocky",
134+
"alien",
135+
"jaws",
57136
]
58137

59138
FOODS = [
60-
"pizza", "sushi", "taco", "lasagna", "pancake", "risotto", "casserole", "burger",
61-
"cupcake", "avocado", "blueberry", "spaghetti", "chocolate"
139+
"pizza",
140+
"sushi",
141+
"taco",
142+
"lasagna",
143+
"pancake",
144+
"risotto",
145+
"casserole",
146+
"burger",
147+
"cupcake",
148+
"avocado",
149+
"blueberry",
150+
"spaghetti",
151+
"chocolate",
62152
]
63153

64154
# merge into categories dict
@@ -163,7 +253,9 @@ def play_round(word, difficulty):
163253
attempts = 0
164254

165255
print("\nScrambled:", " ".join(scrambled))
166-
print(f"(Type your guess, or 'hint', 'skip', 'quit'. Time suggested: {max_time}s)\n")
256+
print(
257+
f"(Type your guess, or 'hint', 'skip', 'quit'. Time suggested: {max_time}s)\n"
258+
)
167259

168260
start = time.perf_counter()
169261
while True:
@@ -190,12 +282,19 @@ def play_round(word, difficulty):
190282
# check answer
191283
if guess == word:
192284
points = compute_score(word, elapsed, difficulty)
193-
print(color(f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})", '32'))
285+
print(
286+
color(
287+
f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})",
288+
"32",
289+
)
290+
)
194291
return points
195292
else:
196293
# small helpful feedback
197294
same_positions = sum(1 for a, b in zip(guess, word) if a == b)
198-
print(f"Not quite. {same_positions} letter(s) in the correct position. Try again.")
295+
print(
296+
f"Not quite. {same_positions} letter(s) in the correct position. Try again."
297+
)
199298

200299

201300
def pick_word_by_difficulty_and_category(difficulty, category=None):
@@ -219,22 +318,25 @@ def celebratory_art():
219318
"\n ★ Congratulations! ★\n",
220319
"\n (\_/)",
221320
"\n ( •_•)",
222-
"\n / >💥 You did it!\n"
321+
"\n / >💥 You did it!\n",
223322
]
224-
print(color('\n'.join(art), '35'))
323+
print(color("\n".join(art), "35"))
225324

226325

227326
def play_game():
228-
print(color("WELCOME TO WORD SCRAMBLE", '36'))
229-
print(color("------------------------", '36'))
327+
print(color("WELCOME TO WORD SCRAMBLE", "36"))
328+
print(color("------------------------", "36"))
230329
# choose difficulty
231330
while True:
232-
diff = input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower() or "medium"
331+
diff = (
332+
input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower()
333+
or "medium"
334+
)
233335
if diff in DIFFICULTIES:
234336
break
235337
print("Invalid choice.")
236338
# choose optional category
237-
print("Available categories:", ', '.join(CATEGORIES.keys()))
339+
print("Available categories:", ", ".join(CATEGORIES.keys()))
238340
cat = input("Pick category (or press Enter for mixed): ").strip().lower() or None
239341
if cat and cat not in CATEGORIES:
240342
print("Unknown category, using mixed words.")
@@ -262,7 +364,12 @@ def play_game():
262364
# combo bonus for streaks: +5% per consecutive correct (rounded)
263365
combo_bonus = int(points * (0.05 * (streak - 1))) if streak > 1 else 0
264366
if combo_bonus:
265-
print(color(f"Combo! +{combo_bonus} bonus points for a streak of {streak}", '33'))
367+
print(
368+
color(
369+
f"Combo! +{combo_bonus} bonus points for a streak of {streak}",
370+
"33",
371+
)
372+
)
266373
points += combo_bonus
267374
total_score += points
268375
celebratory_art()
@@ -291,7 +398,9 @@ def main_menu():
291398
elif choice == "3":
292399
print("\nInstructions:")
293400
print("- Guess the original word from the scrambled letters.")
294-
print("- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'.")
401+
print(
402+
"- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'."
403+
)
295404
print("- Faster correct answers score more points.")
296405
print("- High scores are saved locally in high_scores.json.\n")
297406
elif choice == "4":

0 commit comments

Comments
 (0)