• About
  • Advertise
  • Privacy & Policy
  • Contact
Friday, January 9, 2026
  • Login
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World
    Hillary Clinton in white pantsuit for Trump inauguration

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel
    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
Ai News
Advertisement
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World
    Hillary Clinton in white pantsuit for Trump inauguration

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel
    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
Ai News
No Result
View All Result
Home Machine Learning

Implementing the Rock Paper Scissors Game in Python

AiNEWS2025 by AiNEWS2025
2025-11-27
in Machine Learning
0
Implementing the Rock Paper Scissors Game in Python
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


Introduction to the Game

has been an interesting and on-the-go game since our childhood, one we could play anywhere when bored. The game is simple. It involves two players, and each player has to choose one of the 3 options: Rock, Paper, or Scissors. Rock is expressed using a fist, Scissors with the two fingers spread out, and Paper with the hand opened flat.

The following are the different scenarios that can happen and what they would mean:

  • Rock vs Paper: The Paper covers the Rock. Paper wins.
  • Rock vs Scissors: The Rock breaks the Scissors. Rock wins.
  • Paper vs Scissors: The Scissors cut the Paper. Scissors wins.
  • Same signs: draw!

we will use our understanding of the game, as well as our beginner’s knowledge of Python, to code this game into a computer program. This will be done with the help of Python conditional statements: ‘if’, ‘elif’, and ‘else’, as well as the use of the random module, which is an in-built Python module. We will learn to import it and use its function to include the element of randomness in our game.

Implementing the Game in Python

Now we will implement the game in Python. We will use the concepts of Python Lists and Randomisation using the Python random module to achieve our goal.

This is how the program will proceed:

The program will ask you to choose Rock, Paper or Scissors. The computer will randomly choose one of the 3 choices. Based on the different scenarios above, the program will decide who won the game and will give an option to play again.

Defining the List & Generating the ASCII Art

First, we will generate the ASCII Art for Rock Paper Scissors. We will store these inside variables named correspondingly, which are further stored inside a Python List rps_list.


rock = """
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
"""

paper = """
     _______
---'    ____)____
           ______)
          _______)
         _______)
---.__________)
"""

scissors = """
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
"""

rps_list = [rock, paper, scissors ]
Photo by Fadilah Im on Unsplash

Asking for Input from the User

The next step is to get the input from the user. We will use the variable user_choice to store what the user chooses to play the game with, as well as print it out for the user to see. Notice that the variable user_choice will store the input as a string. This key point will be useful to remember when we use conditionals to compare both the user’s and the computer’s choices in our article ahead.

user_choice = input("What do you choose? Type 'rock' for Rock, 'scissors' for Scissors and 'paper' for Paper")
print(f"User chooses {user_choice}")

Computer’s Random Choice

Once the user has decided their choice, next we will make the computer make a random choice. We will use the random module for this purpose. You can check more about this through the following link:

random — Generate pseudo-random numbers

The random module’s choice() function allows us to randomly make a choice from a given Python list that has been given as a parameter to it. We will store this random choice in the variable computer_choice and print it out.

import random
computer_choice = random.choice(rps_list)
print(f"Computer chooses {computer_choice}")

Moreover, you can also check this article, that tells you how to include randomisation in our code using Python’s random module. It includes an easy explanation of the different functions with easy-to-understand examples:

How to Implement Randomization with the Python Random Module

Scenarios using Conditionals

Now we will define all the different scenarios that we mentioned in the beginning in code form. We will use if, elif, and else, which are Python’s conditional statements, for this purpose.

if computer_choice == rock and user_choice == 'scissors':
    print("You lose")
elif computer_choice == rock and user_choice == 'paper':
    print("You win")
elif computer_choice == rock and user_choice == "rock":
    print("Draw")
elif computer_choice == paper and user_choice == 'paper':
    print("Draw")
elif computer_choice == paper and user_choice == 'scissors':
    print("You win")
elif computer_choice == paper and user_choice == "rock":
    print("You lose")
elif computer_choice == scissors and user_choice == 'scissors':
    print("Draw")
elif computer_choice == scissors and user_choice == "rock":
    print("You win")
elif computer_choice == scissors and user_choice == 'paper':
    print("You lose")
else:
    print("Error")

As can be seen from the code above, we have utilized each and every scenario, comparing the computer’s choice with the user’s choice that had been stored as a string as can be understood from the inverted comma, and then printed out the results, whether the user wins, or the computer wins or it has resulted in a draw between them both.

Conclusion

The above program is a simple Python code, which is easy to understand and gives an introduction to Python’s conditionals and the use of the random module, specifically its choice function.

Although there are a number of ways in which the scenarios could have been coded, the above was an explicit and beginner-friendly code involving the if, elif and else conditionals. Can you think about any other way this game could have been coded?

Source link

#Implementing #Rock #Paper #Scissors #Game #Python

Tags: codingConditional StatementsGamesPythonPython Programming
Previous Post

ULA aimed to launch up to 10 Vulcan rockets this year—it will fly just once

Next Post

Moving toward LessOps with VMware-to-cloud migrations

AiNEWS2025

AiNEWS2025

Next Post
Moving toward LessOps with VMware-to-cloud migrations

Moving toward LessOps with VMware-to-cloud migrations

Stay Connected test

  • 23.9k Followers
  • 99 Subscribers
  • Trending
  • Comments
  • Latest
A tiny new open source AI model performs as well as powerful big ones

A tiny new open source AI model performs as well as powerful big ones

0
Water Cooler Small Talk: The Birthday Paradox 🎂🎉 | by Maria Mouschoutzi, PhD | Sep, 2024

Water Cooler Small Talk: The Birthday Paradox 🎂🎉 | by Maria Mouschoutzi, PhD | Sep, 2024

0
Ghost of Yōtei: The acclaimed Ghost of Tsushima is getting a sequel

Ghost of Yōtei: The acclaimed Ghost of Tsushima is getting a sequel

0
Best Headphones for Working Out (2024): Bose, Shokz, JLab

Best Headphones for Working Out (2024): Bose, Shokz, JLab

0
implications for enterprise strategy in 2026

implications for enterprise strategy in 2026

2026-01-09
The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

2026-01-09
Beyond Prompting: The Power of Context Engineering

Beyond Prompting: The Power of Context Engineering

2026-01-09
Michigan man learns the hard way that “catch a cheater” spyware apps aren’t legal

Michigan man learns the hard way that “catch a cheater” spyware apps aren’t legal

2026-01-09

Recent News

implications for enterprise strategy in 2026

implications for enterprise strategy in 2026

2026-01-09
The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

2026-01-09
Beyond Prompting: The Power of Context Engineering

Beyond Prompting: The Power of Context Engineering

2026-01-09
Michigan man learns the hard way that “catch a cheater” spyware apps aren’t legal

Michigan man learns the hard way that “catch a cheater” spyware apps aren’t legal

2026-01-09
Footer logo

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow Us

Browse by Category

  • AI & Cloud Computing
  • AI & Cybersecurity
  • AI & Sentiment Analysis
  • AI Applications
  • AI Ethics
  • AI Future Predictions
  • AI in Education
  • AI in Fintech
  • AI in Gaming
  • AI in Healthcare
  • AI in Startups
  • AI Innovations
  • AI News
  • AI Research
  • AI Tools & Automation
  • Apps
  • AR/VR & AI
  • Business
  • Deep Learning
  • Emerging Technologies
  • Entertainment
  • Fashion
  • Food
  • Gadget
  • Gaming
  • Health
  • Lifestyle
  • Machine Learning
  • Mobile
  • Movie
  • Music
  • News
  • Politics
  • Review
  • Robotics & Smart Systems
  • Science
  • Sports
  • Startup
  • Tech
  • Travel
  • World

Recent News

implications for enterprise strategy in 2026

implications for enterprise strategy in 2026

2026-01-09
The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

The Download: Mimicking pregnancy’s first moments in a lab, and AI parameters explained

2026-01-09
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.