From f5a1540770388e49d65536352ce1816c406d5229 Mon Sep 17 00:00:00 2001 From: Akshat Raj Anand Date: Thu, 7 Oct 2021 12:55:46 +0530 Subject: [PATCH] New python Mini Project --- .../Rock Paper Scissor Game/README.md | 76 +++++++++++++++++++ Mini Project/Rock Paper Scissor Game/main.py | 57 ++++++++++++++ .../rock_paper_scissor_game.py | 48 ++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 Mini Project/Rock Paper Scissor Game/README.md create mode 100644 Mini Project/Rock Paper Scissor Game/main.py create mode 100644 Mini Project/Rock Paper Scissor Game/rock_paper_scissor_game.py diff --git a/Mini Project/Rock Paper Scissor Game/README.md b/Mini Project/Rock Paper Scissor Game/README.md new file mode 100644 index 0000000..04c5cc4 --- /dev/null +++ b/Mini Project/Rock Paper Scissor Game/README.md @@ -0,0 +1,76 @@ +# Rock Paper Scissor Game🔥 + +- In the rock, paper and scissors game our goal is to create a command-line game where a user has the option to choose between rock, paper and scissors and if the user wins the score is added, and at the end when the user finishes the game, the score is shown to the user. + +## 📌Rock, Paper and Scissors Game with Python + +- To create the Rock, Paper and Scissors game with Python, we need to take the user’s choice and then we need to compare it with the computer choice which is taken using the random module in Python from a list of choices, and if the user wins then the score will increase by 1: + +### Code: + + import random + + choices = ["Rock", "Paper", "Scissor"] + + player = False + cpu_score = 0 + player_score = 0 + + while True: + player = input("Enter your choice ").capitalize() + + computer = random.choice(choices) + + if computer == player: + print("Its tie now...") + + elif player == "Rock": + if computer == "Paper": + print("You lose...", computer, "covers", player) + cpu_score += 1 + + else: + print("You won...", player, "smashes", computer) + player_score += 1 + + elif player == "Paper": + if computer == "Rock": + print("You won...", player, "covers", computer) + player_score += 1 + + else: + print("You lose...", computer, "cut", player) + cpu_score += 1 + + elif player == "Scissor": + if computer == "Paper": + print("You won...", player, "cut", computer) + player_score += 1 + + else: + print("You lose...", computer, "smashes", player) + cpu_score += 1 + + elif player == "End": + print("The final scores are ") + print(f"CPU Score {cpu_score}") + print(f"Player Score {player_score}") + break + + +### Output: + + Enter your choice rock + Its tie now... + Enter your choice paper + You won... Paper covers Rock + Enter your choice scissors + You lose... Rock smashes Scissors + Enter your choice end + The final scores are + CPU Score 1 + Player Score 1 + +## 📌Summary + +- Creating these types of games will help a beginner to think logically. You can even use this idea to make your own game. In the end, creating these types of programs will help you create your algorithms, which is a very important skill for coding interviews and competitive programming. diff --git a/Mini Project/Rock Paper Scissor Game/main.py b/Mini Project/Rock Paper Scissor Game/main.py new file mode 100644 index 0000000..13e89d6 --- /dev/null +++ b/Mini Project/Rock Paper Scissor Game/main.py @@ -0,0 +1,57 @@ +import random + +randNo = random.randint(1,3) +if randNo == 1: + computer_choose = "r" # if randNo is equal to 1 then it will store 'r' as computer choice +if randNo == 2: + computer_choose = "p" # if randNo is equal to 2 then it will store 'p' as computer choice +if randNo == 3: + computer_choose = "s" # if randNo is equal to 3 then it will store 's' as computer choice + +# Defining gameWin function for performing major task for this game. + +def gameWin(computer_choose, user_input): + if computer_choose == user_input: + return None + elif computer_choose == "r": + if user_input == "p": + return True + elif user_input == "s": + return False + + elif computer_choose == "p": + if user_input == "r": + return False + elif user_input == "s": + return True + + elif computer_choose == "s": + if user_input == "r": + return True + elif user_input == "p": + return False + +print("Computer Choosed already from Rock('r') or Paper('p') or Scissor('s')") + +print("Now your turn to choose") + +user_input = input("Choose from Rock('r') or Paper('p') or Scissor('s') ") #taking input from the user + +# It shows the user what computer choose from rock, paper or scissor. +print("Computer choosed " + computer_choose) + +# It shows the user what he/she choose from rock, paper or scissor. +print("You Choosed " + user_input) + + +# This block of if-else statement will find out conditon of gameWin function + +if gameWin(computer_choose, user_input) == None: + print("It tie now") + +elif gameWin(computer_choose, user_input): + print("Congratulations You Won!!!") + +else: + print("You Lose!") + \ No newline at end of file diff --git a/Mini Project/Rock Paper Scissor Game/rock_paper_scissor_game.py b/Mini Project/Rock Paper Scissor Game/rock_paper_scissor_game.py new file mode 100644 index 0000000..c349f5d --- /dev/null +++ b/Mini Project/Rock Paper Scissor Game/rock_paper_scissor_game.py @@ -0,0 +1,48 @@ +import random + +choices = ["Rock", "Paper", "Scissor"] + +player = False +cpu_score = 0 +player_score = 0 + +while True: + player = input("Enter your choice ").capitalize() + + computer = random.choice(choices) + + if computer == player: + print("Its tie now...") + + elif player == "Rock": + if computer == "Paper": + print("You lose...", computer, "covers", player) + cpu_score += 1 + + else: + print("You won...", player, "smashes", computer) + player_score += 1 + + elif player == "Paper": + if computer == "Rock": + print("You won...", player, "covers", computer) + player_score += 1 + + else: + print("You lose...", computer, "cut", player) + cpu_score += 1 + + elif player == "Scissor": + if computer == "Paper": + print("You won...", player, "cut", computer) + player_score += 1 + + else: + print("You lose...", computer, "smashes", player) + cpu_score += 1 + + elif player == "End": + print("The final scores are ") + print(f"CPU Score {cpu_score}") + print(f"Player Score {player_score}") + break \ No newline at end of file