From e117c9b65da86d029aff4214f54a54dcd5da3c06 Mon Sep 17 00:00:00 2001 From: codeasarjun Date: Fri, 6 Sep 2024 10:33:05 +0530 Subject: [PATCH 1/5] rock_paper_scissors project has been added --- projects/rock-paper-scissors/rock_paper_scissors.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 projects/rock-paper-scissors/rock_paper_scissors.py diff --git a/projects/rock-paper-scissors/rock_paper_scissors.py b/projects/rock-paper-scissors/rock_paper_scissors.py new file mode 100644 index 0000000..e69de29 From 0625538ab6f0cf440e38194fe86270c9433167b4 Mon Sep 17 00:00:00 2001 From: codeasarjun Date: Fri, 6 Sep 2024 10:33:40 +0530 Subject: [PATCH 2/5] rock_paper_scissors working code has been added --- .../rock_paper_scissors.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/projects/rock-paper-scissors/rock_paper_scissors.py b/projects/rock-paper-scissors/rock_paper_scissors.py index e69de29..5583a54 100644 --- a/projects/rock-paper-scissors/rock_paper_scissors.py +++ b/projects/rock-paper-scissors/rock_paper_scissors.py @@ -0,0 +1,54 @@ +import random + +def get_computer_choice(): + choices = ['rock', 'paper', 'scissors'] + return random.choice(choices) + +def determine_winner(user_choice, computer_choice): + if user_choice == computer_choice: + return 'draw' + elif (user_choice == 'rock' and computer_choice == 'scissors') or \ + (user_choice == 'paper' and computer_choice == 'rock') or \ + (user_choice == 'scissors' and computer_choice == 'paper'): + return 'user' + else: + return 'computer' + +def play_game(): + print("Welcome to Rock, Paper, Scissors!") + + user_score = 0 + computer_score = 0 + rounds = int(input("How many rounds would you like to play? ")) + + for _ in range(rounds): + user_choice = input("Enter rock, paper, or scissors: ").lower() + if user_choice not in ['rock', 'paper', 'scissors']: + print("Invalid choice, please choose rock, paper, or scissors.") + continue + + computer_choice = get_computer_choice() + print(f"Computer chose: {computer_choice}") + + winner = determine_winner(user_choice, computer_choice) + + if winner == 'user': + print("You win this round!") + user_score += 1 + elif winner == 'computer': + print("Computer wins this round!") + computer_score += 1 + else: + print("This round is a draw!") + + print(f"Scores => You: {user_score} | Computer: {computer_score}") + + if user_score > computer_score: + print(f"Congratulations! You won the game with a score of {user_score} to {computer_score}.") + elif user_score < computer_score: + print(f"Sorry, you lost the game. Final score is You: {user_score} | Computer: {computer_score}.") + else: + print(f"The game is a draw with both scoring {user_score}.") + +if __name__ == "__main__": + play_game() From 1a4b302d1652f6b6335c2c9f6bfa414afe0c226e Mon Sep 17 00:00:00 2001 From: codeasarjun Date: Fri, 6 Sep 2024 10:35:33 +0530 Subject: [PATCH 3/5] rock_paper_scissors info has been added --- projects/rock-paper-scissors/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 projects/rock-paper-scissors/README.md diff --git a/projects/rock-paper-scissors/README.md b/projects/rock-paper-scissors/README.md new file mode 100644 index 0000000..fd272f4 --- /dev/null +++ b/projects/rock-paper-scissors/README.md @@ -0,0 +1,9 @@ +This is a simple Python-based implementation of the classic game where you play against the computer. The game includes features like scorekeeping and multiple rounds. + +## Features + +- Play multiple rounds against the computer. +- Keep track of the score for both the user and the computer. +- Input validation to ensure only valid choices are accepted. +- Display the final result at the end of the game. + From edfba66367d7b5fa7ca12d9de44a1472d496e795 Mon Sep 17 00:00:00 2001 From: codeasarjun Date: Fri, 6 Sep 2024 10:36:35 +0530 Subject: [PATCH 4/5] rock_paper_scissors how to play has been added --- projects/rock-paper-scissors/README.md | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/projects/rock-paper-scissors/README.md b/projects/rock-paper-scissors/README.md index fd272f4..1ce0fe9 100644 --- a/projects/rock-paper-scissors/README.md +++ b/projects/rock-paper-scissors/README.md @@ -7,3 +7,35 @@ This is a simple Python-based implementation of the classic game where you play - Input validation to ensure only valid choices are accepted. - Display the final result at the end of the game. + +## How to Play + +### Start the Game + +When you run the script, you'll be prompted to enter the number of rounds you wish to play. + +### Make Your Choice + +For each round, you will be asked to choose one of the following options: `rock`, `paper`, or `scissors`. + +### Computer's Choice + +The computer will randomly select its choice. + +### Determine the Winner + +The winner of each round is determined based on the classic rules of Rock, Paper, Scissors: + +- **Rock** crushes **Scissors** +- **Scissors** cuts **Paper** +- **Paper** covers **Rock** + +### View Scores + +After each round, the scores will be updated and displayed. + +### End of Game + +At the end of all rounds, the final scores will be displayed, and the winner will be announced. + + From c714c489bd935a7a784dd3ef94782f47ce00f11a Mon Sep 17 00:00:00 2001 From: codeasarjun Date: Fri, 6 Sep 2024 10:37:38 +0530 Subject: [PATCH 5/5] rock_paper_scissors output has been added! --- projects/rock-paper-scissors/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/rock-paper-scissors/README.md b/projects/rock-paper-scissors/README.md index 1ce0fe9..2103ed2 100644 --- a/projects/rock-paper-scissors/README.md +++ b/projects/rock-paper-scissors/README.md @@ -39,3 +39,13 @@ After each round, the scores will be updated and displayed. At the end of all rounds, the final scores will be displayed, and the winner will be announced. +```bash +Welcome to Rock, Paper, Scissors! +How many rounds would you like to play? 3 +Enter rock, paper, or scissors: rock +Computer chose: paper +Computer wins this round! +Scores => You: 0 | Computer: 1 +... +Congratulations! You won the game with a score of 2 to 1. +``` \ No newline at end of file