Skip to content

Commit 3a76186

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

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

web_programming/Word-Scramble-Game.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@
9494
"general": WORD_LIST,
9595
"programming": [w for w in WORD_LIST if w in PROGRAMMING_SET],
9696
"networking": [
97-
w
98-
for w in WORD_LIST
99-
if w in ("network", "protocol", "bandwidth", "packet")
97+
w for w in WORD_LIST if w in ("network", "protocol", "bandwidth", "packet")
10098
],
10199
}
102100

@@ -266,8 +264,7 @@ def play_round(word: str, difficulty: str) -> Union[int, tuple]:
266264

267265
print("\nScrambled:", " ".join(scrambled))
268266
print(
269-
"(Type your guess, or 'hint', 'skip', 'quit'."
270-
f" Time suggested: {max_time}s)\n"
267+
f"(Type your guess, or 'hint', 'skip', 'quit'. Time suggested: {max_time}s)\n"
271268
)
272269

273270
start = time.perf_counter()
@@ -295,12 +292,19 @@ def play_round(word: str, difficulty: str) -> Union[int, tuple]:
295292
# check answer
296293
if guess == word:
297294
points = compute_score(word, elapsed, difficulty)
298-
print(color(f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})", '32'))
295+
print(
296+
color(
297+
f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})",
298+
"32",
299+
)
300+
)
299301
return points
300302
else:
301303
# small helpful feedback
302304
same_positions = sum(1 for a, b in zip(guess, word) if a == b)
303-
print(f"Not quite. {same_positions} letter(s) in the correct position. Try again.")
305+
print(
306+
f"Not quite. {same_positions} letter(s) in the correct position. Try again."
307+
)
304308

305309

306310
def pick_word_by_difficulty_and_category(
@@ -331,16 +335,19 @@ def celebratory_art() -> None:
331335

332336

333337
def play_game() -> None:
334-
print(color("WELCOME TO WORD SCRAMBLE", '36'))
335-
print(color("------------------------", '36'))
338+
print(color("WELCOME TO WORD SCRAMBLE", "36"))
339+
print(color("------------------------", "36"))
336340
# choose difficulty
337341
while True:
338-
diff = input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower() or "medium"
342+
diff = (
343+
input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower()
344+
or "medium"
345+
)
339346
if diff in DIFFICULTIES:
340347
break
341348
print("Invalid choice.")
342349
# choose optional category
343-
print("Available categories:", ', '.join(CATEGORIES.keys()))
350+
print("Available categories:", ", ".join(CATEGORIES.keys()))
344351
cat = input("Pick category (or press Enter for mixed): ").strip().lower() or None
345352
if cat and cat not in CATEGORIES:
346353
print("Unknown category, using mixed words.")
@@ -368,7 +375,12 @@ def play_game() -> None:
368375
# combo bonus for streaks: +5% per consecutive correct (rounded)
369376
combo_bonus = int(points * (0.05 * (streak - 1))) if streak > 1 else 0
370377
if combo_bonus:
371-
print(color(f"Combo! +{combo_bonus} bonus points for a streak of {streak}", '33'))
378+
print(
379+
color(
380+
f"Combo! +{combo_bonus} bonus points for a streak of {streak}",
381+
"33",
382+
)
383+
)
372384
points += combo_bonus
373385
total_score += points
374386
celebratory_art()
@@ -397,7 +409,9 @@ def main_menu() -> None:
397409
elif choice == "3":
398410
print("\nInstructions:")
399411
print("- Guess the original word from the scrambled letters.")
400-
print("- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'.")
412+
print(
413+
"- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'."
414+
)
401415
print("- Faster correct answers score more points.")
402416
print("- High scores are saved locally in high_scores.json.\n")
403417
elif choice == "4":

0 commit comments

Comments
 (0)