Skip to content

New python Mini Project #14

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

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Mini Project/Rock Paper Scissor Game/README.md
Original file line number Diff line number Diff line change
@@ -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.
57 changes: 57 additions & 0 deletions Mini Project/Rock Paper Scissor Game/main.py
Original file line number Diff line number Diff line change
@@ -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!")

48 changes: 48 additions & 0 deletions Mini Project/Rock Paper Scissor Game/rock_paper_scissor_game.py
Original file line number Diff line number Diff line change
@@ -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