[Archived version] I made a rock-paper-scissors game using Python | Learn about if statements and randomness!

programming

"I started using Python, but I don't know what to make..."

For those people, we recommendCreate your own rock-paper-scissors gameis.

This game isA learning material packed with all the basics of programming, such as if statements and random processingWhat's more, even beginners can complete it in about 30 minutes.

In this article, we will explain the steps to create a rock-paper-scissors game using Python.Comes with code and detailed explanationwill be delivered to you.

By reading this article,The joy of running programs with your own handsYou can experience it!

Why make a rock-paper-scissors game with Python?

conclusion

The rock-paper-scissors game isPerfect for beginners to learn basic Python grammar through practiceis.

reason

Flow of if statementscan be intuitively understood

How to use the random moduleYou will learn

• You can see the results immediately after you run it.It is easy to gain successful experience

Examples

For example, if the player plays rock and the computer plays scissors, the code will process the situation and display "win," "lose," or "tie."Comparison operations, branching, standard input and outputWe can cover everything.

reassertion

The rock-paper-scissors game is the perfect first step for Python beginners.

Getting started with Python

conclusion

If you have Python installed, you can quickly create a rock-paper-scissors game.

procedure

1. Install the latest Python from the official Python website

→ https://www.python.org

2. Prepare a text editor (e.g. VSCode, Notepad)

3. Check that you have an environment where you can use the command prompt or terminal

Public agency references:

The Ministry of Education, Culture, Sports, Science and Technology also provides information on "programming education" on the following page:

Guide to programming education in elementary schools: Ministry of Education, Culture, Sports, Science and Technology

reassertion

The biggest appeal of Python is that you can set up the environment for free and try it out right away.

Understand the basic structure of the rock-paper-scissors game

conclusion

The rock-paper-scissors game consists of three parts: selection, judgment, and result display.

Roles of each part

choice: Receives input of "rock," "paper," or "scissors" from the user

judgement: Compare your hand with the computer's hand to determine whether you've won or lost

Results display: Display a message such as "You win!"

Image

1

reassertion

Once you understand these three steps, you'll be able to create a rock-paper-scissors game.

Let's actually write the code and run it

conclusion

You can easily create a rock-paper-scissors game using only basic Python grammar.

Full code example

1

reassertion

Just enter this code and you'll have your own game.

Tips for making rock-paper-scissors games more fun

conclusion

With a little ingenuity, you can make your rock-paper-scissors game even more fun.

Extension Ideas

Added loop functionYou can play it again and again

Save scoreto display the winning percentage

English modeorCharacter NameAdd some fun with

Example of improvement (with score)

1
= {: 0, : 0, : 0}

reassertion

By developing the rock-paper-scissors game, you will naturally acquire Python skills.

FAQ

Q1. Why use "elif"?

A. To clarify the branch. If there is only else, there is a risk of misjudgment.

Q2. Can you make the code shorter?

A. It is possible, but for learning purposes, readability should be prioritized.

Q3. Can it be made using a GUI?

A. Yes. If you use "tkinter" or similar, you can play rock-paper-scissors using a GUI. For more information,HereHere you go.

summary

• Rock-paper-scissors gamePerfect for learning if statements and random processing

• The structure is simple, with just three steps: "select → judge → display"

• By expandingDeepen your understanding of Python and have more fun

• Easy to use, even for beginners, it can be completed in 30 minutes

Copied title and URL