0% found this document useful (0 votes)
15 views

pyp

python

Uploaded by

aryansabale7625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

pyp

python

Uploaded by

aryansabale7625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

INTRODUCTION

Rock, Paper, Scissors is a simple and well-known hand game typically played between two
players. The players at the same time make one of three figures: Rock (fist), Paper (open hand),
or Scissors (fist with the two fingers extended). The winner of the game is decided by the
following rules:

Rock crushes Scissors.


Scissors cut Paper.
Paper covers Rock.
In this Python code, the computer is going to play against the user. The code is going to enable
the user to choose any of the three options, and the computer will choose randomly. Once the
user and computer have chosen their options, the game will compare the two and decide the
result:

Win: The player wins against the computer.


Loss: The player loses to the computer.
Tie: Both the computer and the player play the same move.
The Python programs follow basic principles such as:

User Input: To capture the player’s choice.

Random Module: To allow the computer to select an option randomly. Conditionals: To contrast
the two options and to ascertain the outcome. This is a simple game that will help to reinforce
your Python programming skills, particularly in variable management, input and output, and if
statements.

1
OBJECTIVE

The primary objective of this Python program is to create an interactive game where a player
competes against the computer in the classic Rock, Paper, Scissors game. The program aims to:

1. Allow User Interaction: Prompt the player to input their choice of Rock, Paper,
or Scissors.

2. Random Computer Selection: Enable the computer to randomly select one of the
three options (Rock, Paper, or Scissors).

3. Determine the Winner: Compare the player's choice and the computer’s choice,
and determine the winner based on the following rules:
a. Rock beats Scissors.
b. Scissors beats Paper.
c. Paper beats Rock.

4. Display Results: Output the choices made by both the player and the computer
and announce the outcome of the game (win, loss, or tie).

5. Enhance Python Skills: Provide practice with essential Python concepts such
as variables, input/output, conditionals, and randomization.

2
Tools and Technologies Used in the Python Program

1. Python Programming Language:


a. The core language used to develop the game. Python is simple, versatile, and
ideal for building such interactive programs.
2. IDEs (Integrated Development Environments):
a. IDLE: Python’s built-in IDE, which can be used to write and execute the game.
b. VS Code: A popular code editor with Python extension support.
c. PyCharm: A powerful IDE designed specifically for Python development.
d. Jupyter Notebook: Can also be used to write and test Python code in
an interactive environment, especially helpful for learning.
3. Python Libraries:
a. random: This standard Python library is used to randomly select a choice for
the computer (Rock, Paper, or Scissors). It is essential for simulating the
computer's unpredictable selection in the game.
4. Command-Line Interface (CLI):
a. The game can be run and interacted with through a terminal or command
prompt. The player will input their choice via the console, and the program will
display the results directly on the screen.
5. Text-based Output:
a. The program displays results (win, lose, tie) and choices made by the player
and the computer through the console using Python’s print() function.

Technologies Involved:
 Python Version: The game can be developed with any version of Python 3.x.
 Operating System: The program can be run on any operating system (Windows,
macOS, Linux) with Python installed.

Optional Advanced Features (For Extended Learning):

1. Graphical User Interface (GUI):


a. Tkinter: A library for building simple graphical user interfaces, allowing
the game to be played with buttons instead of text input/output.
2. Version Control:
a. Git: Version control software to manage changes and collaborate if the project is
extended or worked on by multiple people.

3
PROGRAM

import random

user_wins = 0 computer_wins = 0

options = ["rock", "paper",

"scissors"]

while True: user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower() if user_input


== "q": break

if user_input not in options:


continue

random_number =
random.randint(0, 2) # rock: 0,
paper: 1, scissors: 2
computer_pick = options[random_number]
print("Computer picked",
computer_pick + ".")

if user_input == "rock" and computer_pick == "scissors":


print("You won!")
user_wins += 1

elif user_input == "paper" and computer_pick == "rock":


print("You won!")
user_wins += 1

elif user_input == "scissors" and computer_pick == "paper":


print("You won!")
user_wins += 1

else:
print("You lost!")
computer_wins += 1

print("You won", user_wins, "times.") print("The computer won", computer_wins, "times.")


print("Thankyou!")

4
OUTPUT

Type Rock/Paper/Scissors or Q to quit: Rock


Computer picked scissors.
You won!
Type Rock/Paper/Scissors or Q to quit: Paper
Computer picked rock.
You won!
Type Rock/Paper/Scissors or Q to quit: Rock
Computer picked scissors.
You won!
Type Rock/Paper/Scissors or Q to quit: Scissors
Computer picked scissors.
You lost!
Type Rock/Paper/Scissors or Q to quit: Paper
Computer picked paper.
You lost!
Type Rock/Paper/Scissors or Q to quit: Scissors
Computer picked paper.
You won!
Type Rock/Paper/Scissors or Q to quit: Q
You won 4 times.
The computer won 2 times.
Thankyou!

5
CONCLUSION

The Rock, Paper, Scissors game in Python is a fun and simple project that helps reinforce key
programming concepts such as user input handling, conditionals, loops, and randomization. By
implementing this game, we have created an interactive and engaging experience where a player
can compete against the computer, while practicing fundamental skills like decision-making
logic and game flow control.

Through this program, we’ve:

 Allowed the player to make choices and interact with the computer.
 Used random number generation to simulate the computer's decisions.
 Implemented conditions to determine the outcome of each round.
 Incorporated optional features such as score tracking and a game loop for
multiple rounds.

Additionally, there’s room to expand this project by adding advanced features like a
graphical user interface (GUI), difficulty levels, or multiplayer modes, which would further
enhance the game and provide more opportunities for learning.

Overall, this Python program serves as a great starting point for beginners, offering valuable
experience in problem-solving, code structure, and user interaction. It can be modified and
extended to create even more complex and interactive games, paving the way for future
programming projects.

You might also like