Decide winner of one round. Parameters ---------- user : str User's choice ("s", "w", "g"). computer : str Computer's choice ("s", "w", "g"). Returns ------- str "user", "computer", or "draw".
(user: str, computer: str)
| 36 | |
| 37 | |
| 38 | def determine_winner(user: str, computer: str) -> str: |
| 39 | """ |
| 40 | Decide winner of one round. |
| 41 | |
| 42 | Parameters |
| 43 | ---------- |
| 44 | user : str |
| 45 | User's choice ("s", "w", "g"). |
| 46 | computer : str |
| 47 | Computer's choice ("s", "w", "g"). |
| 48 | |
| 49 | Returns |
| 50 | ------- |
| 51 | str |
| 52 | "user", "computer", or "draw". |
| 53 | """ |
| 54 | if user == computer: |
| 55 | return "draw" |
| 56 | |
| 57 | if user == "s" and computer == "w": |
| 58 | return "computer" |
| 59 | if user == "w" and computer == "s": |
| 60 | return "user" |
| 61 | |
| 62 | if user == "g" and computer == "s": |
| 63 | return "user" |
| 64 | if user == "s" and computer == "g": |
| 65 | return "computer" |
| 66 | |
| 67 | if user == "w" and computer == "g": |
| 68 | return "user" |
| 69 | if user == "g" and computer == "w": |
| 70 | return "computer" |
| 71 | |
| 72 | return "invalid" |
| 73 | |
| 74 | |
| 75 | def play_game(rounds: int = 10) -> None: |