Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 51k
Feat/snake water gun game#13658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Feat/snake water gun game #13658
Changes from all commits
2b3d13f4f6c51668d08f8bd4324fa30f6b7cb64f9d66be858da4124b9bfb9abe50ff0ace8f891File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| A simple implementation of the Snake, Water, Gun game. | ||
| """ | ||
| import doctest | ||
| import random | ||
| def snake_water_gun(player_choice: str, computer_choice: str) -> str: | ||
| """ | ||
| Determines the winner of a Snake, Water, Gun game round. | ||
| Args: | ||
| player_choice: The player's choice ('s' for snake, 'w' for water, 'g' for gun). | ||
| computer_choice: The computer's choice. | ||
| Returns: | ||
| Result: "Player wins!", "Computer wins!", or "It's a draw!". | ||
| Doctests: | ||
| >>> snake_water_gun('s', 'w') | ||
| 'Player wins!' | ||
| >>> snake_water_gun('w', 'g') | ||
| 'Player wins!' | ||
| >>> snake_water_gun('g', 's') | ||
| 'Player wins!' | ||
| >>> snake_water_gun('w', 's') | ||
| 'Computer wins!' | ||
| >>> snake_water_gun('s', 's') | ||
| "It's a draw!" | ||
| """ | ||
| if player_choice == computer_choice: | ||
| return "It's a draw!" | ||
| if ( | ||
| (player_choice == "s" and computer_choice == "w") | ||
| or (player_choice == "w" and computer_choice == "g") | ||
| or (player_choice == "g" and computer_choice == "s") | ||
| ): | ||
| return "Player wins!" | ||
| else: | ||
| return "Computer wins!" | ||
| def main(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: | ||
| """ | ||
| Main function to run the Snake, Water, Gun game. | ||
| """ | ||
| print("--- Snake, Water, Gun Game ---") | ||
| player_input = ( | ||
| input("Enter your choice (s for snake, w for water, g for gun): ") | ||
| .lower() | ||
| .strip() | ||
| ) | ||
| if player_input not in ["s", "w", "g"]: | ||
| print("Invalid choice. Please choose 's', 'w', or 'g'.") | ||
| return | ||
| choices = ["s", "w", "g"] | ||
| computer_input = random.choice(choices) | ||
| print(f"\nYou chose: {player_input}") | ||
| print(f"Computer chose: {computer_input}\n") | ||
| result = snake_water_gun(player_input, computer_input) | ||
| print(result) | ||
| if __name__ == "__main__": | ||
| doctest.testmod() # Run the doctests | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
main. If the function does not return a value, please provide the type hint as:def function() -> None:As there is no test file in this pull request nor any test function or class in the file
other/snake_water_gun.py, please provide doctest for the functionmain