1010import random
1111from 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+
3741def 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"\n Round { 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+
89100if __name__ == "__main__" :
90101 main ()
0 commit comments