Close Menu
    Trending
    • Optimizing Data Transfer in Distributed AI/ML Training Workloads
    • Achieving 5x Agentic Coding Performance with Few-Shot Prompting
    • Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found
    • From Transactions to Trends: Predict When a Customer Is About to Stop Buying
    • America’s coming war over AI regulation
    • “Dr. Google” had its issues. Can ChatGPT Health do better?
    • Evaluating Multi-Step LLM-Generated Content: Why Customer Journeys Require Structural Metrics
    • Why SaaS Product Management Is the Best Domain for Data-Driven Professionals in 2026
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Implementing the Rock Paper Scissors Game in Python
    Artificial Intelligence

    Implementing the Rock Paper Scissors Game in Python

    ProfitlyAIBy ProfitlyAINovember 27, 2025No Comments5 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Introduction to the Recreation

    has been an attention-grabbing and on-the-go recreation since our childhood, one we might 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 reduce the Paper. Scissors wins.
    • Similar indicators: draw!

    we’ll use our understanding of the sport, in addition to our newbie’s information of Python, to code this recreation into a pc program. This will probably be carried out 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’ll be taught to import it and use its operate to incorporate the factor of randomness in our recreation.

    Implementing the Recreation in Python

    Now we’ll implement the sport in Python. We’ll use the ideas of Python Lists and Randomisation utilizing the Python random module to realize 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 selections. Primarily based on the completely different eventualities above, this system will resolve who gained the sport and can give an choice to play once more.

    Defining the Listing & Producing the ASCII Artwork

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

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

    Asking for Enter from the Consumer

    The following step is to get the enter from the consumer. We’ll use the variable user_choice to retailer what the consumer chooses to play the sport with, in addition to print it out for the consumer to see. Discover that the variable user_choice will retailer the enter as a string. This key level will probably be helpful to recollect after we use conditionals to match each the consumer’s and the pc’s selections in our article forward.

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

    Pc’s Random Alternative

    As soon as the consumer has determined their selection, subsequent we’ll make the pc make a random selection. We’ll use the random module for this goal. You possibly can verify extra about this by way of the next hyperlink:

    random — Generate pseudo-random numbers

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

    import random
    computer_choice = random.selection(rps_list)
    print(f"Pc chooses {computer_choice}")

    Furthermore, you may as well verify this text, that tells you methods to embrace randomisation in our code utilizing Python’s random module. It contains a straightforward rationalization of the completely different features 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 type. We’ll use if, elif, and else, that are Python’s conditional statements, for this goal.

    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 now have utilized every situation, evaluating the pc’s selection with the consumer’s selection 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 consumer 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 straightforward to know and provides an introduction to Python’s conditionals and the usage of the random module, particularly its selection operate.

    Though there are a variety of how by which the eventualities might have been coded, the above was an specific and beginner-friendly code involving the if, elif and else conditionals. Can you consider some other means this recreation might have been coded?



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleI Cleaned a Messy CSV File Using Pandas .  Here’s the Exact Process I Follow Every Time.
    Next Article Everyday Decisions are Noisier Than You Think — Here’s How AI Can Help Fix That
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026
    Artificial Intelligence

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026
    Artificial Intelligence

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    What Is Sociophonetics and Why It Matters for AI

    December 9, 2025

    Using Claude Skills with Neo4j | Towards Data Science

    October 28, 2025

    Why 90% Accuracy in Text-to-SQL is 100% Useless

    January 12, 2026

    ByteDance’s Seaweed-7B videogenerering i miniformat

    April 17, 2025

    Unlock Global AI: Why Multilingual AI Text Data is Crucial

    April 3, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    Image Annotation – Key Use Cases, Techniques, and Types [2025]

    April 5, 2025

    5 Ways Data Quality Can Impact Your AI Solution

    May 28, 2025

    Google’s URL Context Grounding: Another Nail in RAG’s Coffin?

    August 26, 2025
    Our Picks

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

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