X

    Get a Quote

    How to Make Rock Paper Scissors in Python | Intermediate Python Tutorial

    458 views
    Amit Shukla

    Project Introduction

    Let’s learn how to code a classic game in Python. We’re going to use conditionals, while loops, and random numbers to make a Rock, Paper, Scissors game where you play against the computer! Watch the tutorial video to see how we code this game step-by-step and continue reading this post for more details.

    Who is this project for?

    This project falls under our Juni Python Level 2 coding class for kids. This intermediate Python tutorial is for students that want an Easy challenge project, about ~60 lines of code long. You should review print(), input(), and variables beforehand to get the most out of this project.

    Some other projects you can try first for more practice with intermediate Python are our Python pet simulator and make a calculator in tutor app development company.

    For learning outcomes, you’ll get a lot of practice with conditionals, while loops, and random numbers. This project is estimated to take you about, but you should move faster or slower at your own pace!

    5 Best Python Natural Language Processing Libraries

    Project Demo

    Before getting started, see how our finished project works for reference. Watch the video, or click run to see the project yourself!

    You can also view my project solution code if you get stuck.

    What to keep in mind before you start:

    • You can play the game over and over until you choose to stop.
    • The program keeps track of wins.
    • The case doesn’t matter (i.e. ROCK is the same as a rock).
    • If you enter something invalid, the program keeps prompting you until you enter something valid.

    Steps to Code the Project:

    1. Create a simple, one-round version of the game where we don’t enforce correct inputs.
    2. Add while loops to re-prompt the user to enter their choice if they type something invalid.
    3. Use a while loop to let the user play over and over, and use variables to keep track of the scores.

    Make Your Own Virtual Zoom Background | Beginner Python Coding Tutorial

    How do we do each of these steps?

    Step 1: Create a simple, one-round version of the game where we don’t enforce correct inputs.

    • Use randint() to generate a random number, and use conditionals to let each random number choose a different option for the computer (e.g. 0 mean rock, 1 means paper, 2 means scissors).
    • Use input() to get the user’s choice.
    • Use conditionals to see who wins.

    Hint: Break it down into cases! If the user chooses rock, then there are possibilities depending on what the computer picked. You can use and, or nested conditionals!

    Step 2: Add while loops to re-prompt the user to enter their choice if they type something invalid.

    • Use .lower() on the user’s input to make sure our stored value is always lowercase.
    • Write code so that while the user’s input is not one of the valid choices, it keeps prompting them to re-enter their choice.

    Step 3: Use a while loop to let the user play over and over, and use variables to keep track of the scores.

    • Use while True to create a loop that runs forever.
    • After the end of the round, ask the user if they want to keep playing; if they say no, use the break to end the loop.
    • Use the same strategy from step 2 (.lower() and a while loop) to enforce a valid input for this choice too!
    • Before the while, True loop, create variables to keep track of the scores and increment those variables in the right places.

    Challenge Yourself with Extra Features

    Creative Suggestions

    • Rewrite the program to be a two-player game instead of one player vs. the computer.
    • Modify your random-number-generation and conditionals to change the probability of each choice for the computer!

    Need more help, or want to keep learning?

    Great job! Check out more coding tutorials

    Thanks for watching and hope you had fun making this project with me! Every week, we’ll be posting project tutorials like app this one, for different coding languages and experience levels, as well as math tutorials.

    Check out our step-by-step coding projects to find our other tutorials in Python and more coding languages!

    Hire Python Developers

    Need more help, or want to keep learning?

    Looking up your coding questions is one of the best ways to learn! Another great way to learn is from an experienced coder or instructor.

    Juni Learning Coding Instructors like Maya work closely with students ages 8-18 and are specially trained to adapt to each child’s unique learning style, pace, and interests.

    Read more about our online coding classes for kids and curriculum, or contact our Admissions Team to learn which course is best for your student’s coding journey.

    Web Development Company ad

    Thanks for reading our post “How to Make Rock Paper Scissors in Python | Intermediate Python Tutorial”, please connect with us for any further inquiry. We are Next Big Technology, a leading web & Mobile Application Development Company. We build high-quality applications to full fill all your business needs.

    Avatar for Amit
    The Author
    Amit Shukla
    Director of NBT
    Amit Shukla is the Director of Next Big Technology, a leading IT consulting company. With a profound passion for staying updated on the latest trends and technologies across various domains, Amit is a dedicated entrepreneur in the IT sector. He takes it upon himself to enlighten his audience with the most current market trends and innovations. His commitment to keeping the industry informed is a testament to his role as a visionary leader in the world of technology.