0 ratings0% found this document useful (0 votes) 66 views11 pagesComputer Application
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
BEASANT
TECHNOLOGIES
A Project reportes
On
“ROCK PAPER SCISSORS”
For the course
PYTHON PROGRAMMIN NG
LANGUAGE
2 ssn y
- PAVITHRA G
SUBMITTED TO COORDINATOR
GOWTHAMI INBA
@ scanned with OKEN ScannerCONCEPT OF ROCK paper scissior
Python program to implement Rock Paper Scissors game python is a multipurpose language any
one can do anything with it python can also be used for game development.let's create a simple
command-line Rock-paper-scissior game without using any external game, user gets the first chance
pick the option between Rock,Paper,and Scissors.After the computer select from the remaining two
choices(randomly),the winner is decided as per the rules
Winning rules as follows:
Rock vs paper->paper wins
Rock vs Scissor->Rock wins
Paper vs Scissor->Scissor wins
BASIC ROCK PAPER SCISSORS PYTHON PROGRAM
To understand the program below, you should have a basic idea
About the following python concepts:
> Python Random module
> python loops
Play a single game of rock paper scissors in python
Using the description and rules above,you can make a game of
Rock paper scissors. before you dive in you're going to need to import
The module you ‘Il use to simulate the computer's choices:
Import random
Awesome! Now you're able to use the different tools inside random
To randomize the computer's actions in the game. Now what? Since You
need to be able to choose their action .
@ scanned with OKEN ScannerSOURCE CODE:
Ty 3 x
te Yor totems oe Bee
auael £/ M4) ZIG 8 Pik 6/9 9\clm| 2l@
1 Fore. and
2 print(*\relcone to Rock, Paper, Scissors!")
3 player-eine =
2 gahite Troet,
+ Po ptayer = inevecrintnter » choice (rock, paper, sctasors)! ")
+ | Gholees = Cerock"y spupersy sactsors"]
+ | Soputer = candonchoice(chosces)
+ | prinecf"\nvou chose (player), computer chose (comuter)")
Bf af player = computers
2 princ(foBoth players selected (player). Te 4s a tie!*)
Bb elit player = reece
1 conuter = "aeissorst
. print("Rock aneshes scissors. You wit")
* player wtnert
" eset
prine(*Paper covers rock, You lose.)
Bh ati player
i 4 contr
2 print("Paper covers rock. You win")
i Player wine
IM tset
te prine("Setssors cut
t Computer xine
= rine(scieere cate papers You win")
a player wiaecl
m eset
Print(“Rock anashes scissors. You Lose")
fe emptor ie
ss | prinecs\nvou have *este(ptayerwins)+* wins")
se | prinetthe conuter has "+str(computer wins) wins
a8 input("\nPlay again? (yes/no): ")
3 ower)
ie prine(*Thank
ls Break
letras cats 1/8 tal Sd n= Cee = LED Une CRE HS 5 Penton
@ scanned with OKEN ScannerDESCRIPTION CODE:
Step 1: Open a text editor
Step 2: Use the import statement
import random
The import statement loads module contents for later access and use. When an import
statement is executed, the standard built-in _import_( function is called. The random
module is a built-in module to generate random variables. We are going to use it to make
computer choose a random value among rock, paper, and scissors each game we play.
Step 3: Print introduction line
print("Welcome to Rock, Paper, Scissors! \n")
Make sure to use double quotes because strings must be enclosed in double quotes for the
data to be recognized as a string, not a number or variable name.
A backslash n (\n) is called a new line and used inside the print statement to create a new line
as its name indicates.
Step 4: Set win counters
player_wins =0
computer_wins = 0
Assign a value of 0 to win counter variables.
Step 5: Use While statement
while True:
player = input("Enter a choice (rock, paper, scissors): ")
choices = ["rock", "paper", "scissors"]
@ scanned with OKEN Scannercomputer = random.choice(choices)
print(f"\nYou chose {player}, computer chose {computer}.")
While True means loop forever. In other words, the while loop will run as long as the While
condition is True. You can force the loop to end by using the break statement.
Create an input variable where players can enter a value among rock, paper, scissors.
Create a list containing the rock, paper, scissors values with brackets. We will call the list
“choices”.
Then, we are going to use the random module here. Create a random.choice variable. The
choice() function here is used to randomly select an item from a list.
Print the game status information .The fwith curly braces is called f-string,and it lets you include
The value python expression inside a string.
Step 6: Use if statement
If player==computer:
Print(“both players selected{player}.it is a tie!”)
Elif player=="rock”:
If computer =="scissiors”:
Print(“Rock smashes scissord.You win!”)
Player_wins+1
Else:
Print(“paper covers rock.you lose.”)
Computer_wins+=1
@ scanned with OKEN Scannerprint("Paper covers rock. You win!")
player_wins+=1
else:
print("Scissors cuts paper. You lose.")
computer_wins+=1
elif player == "scissors":
if computer == "paper":
print("Scissors cuts paper. You win!")
player_wins+=1
else:
print("Rock smashes scissors. You lose.")
computer_wins+=1
Note that an if block can go under another if block.
Step 7: Print the win counters
print("You have "+str(player_wins)+" wins")
print("The computer has "+str(computer_wins)+" wins")
The str() function converts the specified value into a string. Instead of the str() function, you can
use f-strings as follows:
print(f"You have {player_wins} wins")
print(f"The computer has {computer_wins} wins")
@ scanned with OKEN ScannerStep 8: Ask to quit or play again
repeat = input(""\nPlay again? (yes/no): ")
if repeat.lower() != "yes":
print("Thanks for playing!")
break
Create a repeat variable where players can enter a value between yes or no. The lower()
method returns the lowercase string from the given string.
The exclamation mark with an equal sign (!=) is called not equal to operator. If players enter any
value other than yes, the while statement stops operating because of the following break
statement.
The break statement terminates the current loop. It can be used in both while and for loops.
Congratulations! You've just built a rock-paper-scissors game in Python.
Below is the entire code:
Below is the entire code:
import random
print("Welcome to Rock, Paper, Scissors!\n")
player_wins =0
computer_wins=0
while True:
player=input(“Enter a choice(rock,paper,scissors):”)
choices=[“rock”,”paper”,”scissors”]
computer=random.choice(choices)
@ scanned with OKEN Scannerprint(“f’\nYou choose{player},computer choose{computer}.”)
if player == computer:
print(f"Both players selected {player}. It is a tie!")
©
if player == "rock":
if computer == "scissors":
rint("Rock smashes scissors. You win!")
p
player_wins+=1
else:
p
rint("Paper covers rock. You lose.")
computer_wins+=1
e
if player
if computer ==
rint("Paper covers rock. You win!")
p
player_wins+=1
else:
p
rint("Scissors cuts paper. You lose.")
computer_wins+=1
©
if player == "scissors":
if computer == "paper":
print("Scissors cuts paper. You win!")
player_wins+=1
else:
@ scanned with OKEN Scannerprint("Rock smashes scissors. You lose.")
computer_wins+=1
print("You have "+str(player_wins)+" wins")
print('The computer has "+str(computer_wins)+" wins") repeat =
input("\nPlay again? (yes/no): ")
if repeat.lower() != "yes":
print ("Thanks for playing!")
Break
@ scanned with OKEN ScannerOUTPUT:
Scanned with OKEN ScannerCONCLUSION:
We have learned what a rock, paper and scissors game
is and the rules to play this game. We also learnt how to create a
simple rock paper scissor game in Python.
While this game in python may seem basic, it’s a great starting
point for learning programming concepts like conditional
statements, functions, and modules.
As you become more comfortable with Python, you can add more
features to the game, such as keeping score, allowing inputs
from the users that are not case sensitive and allowing the user
to play multiple rounds.
With a little creativity, you can create a fun and engaging game
that people will enjoy playing.Coding for kids has many
beneficial advantages that clevelop cognitive abilities, enhance
communication and entrepreneurship skills, and stimulate
creativity. Kids can learn how to create different games using
@ scanned with OKEN Scanner