Skip to content

Commit 241376a

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

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

snake-game/snake_game.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import random
1111
from typing import Literal
1212

13-
def snake_water_gun(user_choice: Literal['s', 'w', 'g'], computer_choice: Literal['s', 'w', 'g']) -> str:
13+
14+
def snake_water_gun(
15+
user_choice: Literal["s", "w", "g"], computer_choice: Literal["s", "w", "g"]
16+
) -> str:
1417
"""
1518
Determines the winner between user and computer.
1619
@@ -30,10 +33,11 @@ def snake_water_gun(user_choice: Literal['s', 'w', 'g'], computer_choice: Litera
3033
"""
3134
if user_choice == computer_choice:
3235
return "Draw"
33-
if (user_choice, computer_choice) in [('s', 'w'), ('w', 'g'), ('g', 's')]:
36+
if (user_choice, computer_choice) in [("s", "w"), ("w", "g"), ("g", "s")]:
3437
return "You win!"
3538
return "Computer wins!"
3639

40+
3741
def main() -> None:
3842
"""
3943
Main function to run the Snake-Water-Gun game with multiple rounds.
@@ -43,7 +47,9 @@ def main() -> None:
4347

4448
while True:
4549
try:
46-
rounds = int(input("Enter the number of rounds you want to play (1-10): ").strip())
50+
rounds = int(
51+
input("Enter the number of rounds you want to play (1-10): ").strip()
52+
)
4753
if 1 <= rounds <= 10:
4854
break
4955
else:
@@ -53,12 +59,16 @@ def main() -> None:
5359

5460
score_user = 0
5561
score_computer = 0
56-
choices = ['s', 'w', 'g']
62+
choices = ["s", "w", "g"]
5763

5864
for round_number in range(1, rounds + 1):
5965
print(f"\nRound {round_number}:")
6066
while True:
61-
user_input = input("Enter your choice: s for Snake, w for Water, g for Gun: ").strip().lower()
67+
user_input = (
68+
input("Enter your choice: s for Snake, w for Water, g for Gun: ")
69+
.strip()
70+
.lower()
71+
)
6272
if user_input in choices:
6373
break
6474
else:
@@ -86,5 +96,6 @@ def main() -> None:
8696
else:
8797
print("It's a tie!")
8898

99+
89100
if __name__ == "__main__":
90101
main()

0 commit comments

Comments
 (0)