Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • From Regex to Vision Models: Which RAG Technique Fits Which Problem
    • Rehumanizing global health care with agentic AI
    • Robots-Blog | Praxisprojekt mit fischertechnik an der Hochschule Hof in Bayern
    • Ancient giant octopuses were apex predators, study finds
    • Barcelona’s Zazume raises €2.5 million to scale its AI-powered rental management platform
    • How to Shop Like a Pro During Amazon Prime Day (2026)
    • CFTC seeks injunction in Kalshi Rhode Island dispute
    • As AI Expands, Erin Brockovich Taps Communities to Map Data Center Concerns
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Tuesday, June 2
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»Implementing the Rock Paper Scissors Game in Python
    Artificial Intelligence

    Implementing the Rock Paper Scissors Game in Python

    Editor Times FeaturedBy Editor Times FeaturedNovember 28, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    Introduction to the Sport

    has been an fascinating and on-the-go recreation since our childhood, one we may play anyplace when bored. The sport is straightforward. It entails two gamers, and every participant has to decide on one of many 3 choices: Rock, Paper, or Scissors. Rock is expressed utilizing a fist, Scissors with the 2 fingers unfold out, and Paper with the hand opened flat.

    The next are the completely different eventualities that may occur and what they’d imply:

    • 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 lower the Paper. Scissors wins.
    • Similar indicators: draw!

    we’ll use our understanding of the sport, in addition to our newbie’s data of Python, to code this recreation into a pc program. This can be finished with the assistance of Python conditional statements: ‘if’, ‘elif’, and ‘else’, in addition to the usage of the random module, which is an in-built Python module. We are going to be taught to import it and use its operate to incorporate the ingredient of randomness in our recreation.

    Implementing the Sport in Python

    Now we’ll implement the sport in Python. We are going to use the ideas of Python Lists and Randomisation utilizing the Python random module to attain our purpose.

    That is how this system will proceed:

    This system will ask you to decide on Rock, Paper or Scissors. The pc will randomly select one of many 3 decisions. Based mostly on the completely different eventualities above, this system will determine who received the sport and can give an choice to play once more.

    Defining the Record & Producing the ASCII Artwork

    First, we’ll generate the ASCII Artwork for Rock Paper Scissors. We are going to retailer these inside variables named correspondingly, that are additional saved inside a Python Record rps_list.

    
    rock = """
        _______
    ---'   ____)
          (_____)
          (_____)
          (____)
    ---.__(___)
    """
    
    paper = """
         _______
    ---'    ____)____
               ______)
              _______)
             _______)
    ---.__________)
    """
    
    scissors = """
        _______
    ---'   ____)____
              ______)
           __________)
          (____)
    ---.__(___)
    """
    
    rps_list = [rock, paper, scissors ]
    Photograph by Fadilah Im on Unsplash

    Asking for Enter from the Person

    The subsequent step is to get the enter from the person. We are going to use the variable user_choice to retailer what the person chooses to play the sport with, in addition to print it out for the person to see. Discover that the variable user_choice will retailer the enter as a string. This key level can be helpful to recollect once we use conditionals to check each the person’s and the pc’s decisions in our article forward.

    user_choice = enter("What do you select? Sort 'rock' for Rock, 'scissors' for Scissors and 'paper' for Paper")
    print(f"Person chooses {user_choice}")

    Laptop’s Random Alternative

    As soon as the person has determined their alternative, subsequent we’ll make the pc make a random alternative. We are going to use the random module for this objective. You possibly can examine extra about this by the next hyperlink:

    random — Generate pseudo-random numbers

    The random module’s alternative() operate permits us to randomly choose from a given Python listing that has been given as a parameter to it. We are going to retailer this random alternative within the variable computer_choice and print it out.

    import random
    computer_choice = random.alternative(rps_list)
    print(f"Laptop chooses {computer_choice}")

    Furthermore, it’s also possible to examine this text, that tells you find out how to embrace randomisation in our code utilizing Python’s random module. It consists of a straightforward rationalization of the completely different capabilities with easy-to-understand examples:

    How to Implement Randomization with the Python Random Module

    Situations utilizing Conditionals

    Now we’ll outline all of the completely different eventualities that we talked about to start with in code kind. We are going to use if, elif, and else, that are Python’s conditional statements, for this objective.

    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 could be seen from the code above, we’ve got utilized every state of affairs, evaluating the pc’s alternative with the person’s alternative that had been saved as a string as could be understood from the inverted comma, after which printed out the outcomes, whether or not the person wins, or the pc wins or it has resulted in a draw between them each.

    Conclusion

    The above program is an easy Python code, which is simple to grasp and provides an introduction to Python’s conditionals and the usage of the random module, particularly its alternative operate.

    Though there are a selection of how wherein the eventualities may have been coded, the above was an specific and beginner-friendly code involving the if, elif and else conditionals. Can you consider some other approach this recreation may have been coded?



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    From Regex to Vision Models: Which RAG Technique Fits Which Problem

    June 2, 2026

    Escaping the Valley of Choice in BI

    June 2, 2026

    Ensuring Data Integrity with Cryptographic Hashing and the Ethereum Blockchain

    June 1, 2026

    RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem

    June 1, 2026

    How to Combine Claude Code and Codex for Maximum Coding Power

    June 1, 2026

    It’s the Lessons We Learned Along the Way. Or, Is It?

    June 1, 2026

    Comments are closed.

    Editors Picks

    From Regex to Vision Models: Which RAG Technique Fits Which Problem

    June 2, 2026

    Rehumanizing global health care with agentic AI

    June 2, 2026

    Robots-Blog | Praxisprojekt mit fischertechnik an der Hochschule Hof in Bayern

    June 2, 2026

    Ancient giant octopuses were apex predators, study finds

    June 2, 2026
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    Human chin may be an evolutionary byproduct

    March 30, 2026

    New algae gel boosts coral larvae settlement on damaged reefs

    May 26, 2025

    Generating Structured Outputs from LLMs

    August 8, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

    Type above and press Enter to search. Press Esc to cancel.