I started studying Python3 because my self-restraint life has been prolonged and I don't want to spend a gloomy day without doing anything. Python is a language, but applications of that language include stand-alone scripts, cloud services, games, and science and technology calculation. There is a wide range up to .html). For the time being, I would like to learn python while looking back from the basics of the program.
This article was written to teach my son, but it seems that Qiita is more responsive than I expected, so there are many people who want to teach the program to their children or who want to study the program more easily. I felt it. Since writing this article, my son has come to express everyday life programmatically. As I write below, the basis of the program is only "behavior, condition, repetition". That's why I programmatically express my mom's anger and begging for pocket money to make me laugh. On the other hand, my son's ambition is big ** "I want to make a game like Fortnite!" **. That's fine, of course, but suddenly having a big goal can be frustrating. This is the same as saying, "You can't understand the English legal terminology dictionary without first studying English." "If you understand the language of Python and the nature of the program, you'll be able to start programming with 3D modeling like Unity, but it's going to be too difficult to get in from Unity." The program I wrote here was made faithfully to this foundation so as not to deviate from "behavior, condition, repetition" as much as possible. So please forgive any code that you feel is redundant. You can modify the source code described here as much as you like and use it as you like. Let's get started.
When learning programming, I often wonder whether to learn a language or a library. In many of today's advanced programming development environments, understanding libraries and classes is more important than language itself. In terms of language, if you can understand c, c ++, java, and php, python seems to be a relatively easy language.
By the way, I think the most boring and least useful sample program in studying a programming language is a program called Hello World. There is no sample program that discourages learners so much when studying programs.
So this content doesn't use Hello World. Instead, I would like to make an Othello game.
No matter what language you use, there are only three basics you need to program.
Basics | Description |
---|---|
Action (control statement) | Take a step forward |
Judgment (conditional statement) | Do you hit the wall? |
Repeat (loop) | Repeat a certain number of times, repeat forever |
It looks like this when written like a program. The program will rotate to the right when it hits a wall and will continue until then. Since it repeats forever, it will be a program that will keep walking for the rest of your life. Yes, this is the end of studying the basics of the program.
Repeat forever {
Do you hit the wall?
Yes: Rotate your body to the right
No: Take a step forward
}
If you want to learn Python, this is the only thing you need to explain in advance.
Python enforces the structuring of a language called indentation. This makes it possible to create programs that are easy to read and do not become redundant as a creator. For Python, indent to indicate that the condition is a block of matching programs. In the following program, if the condition is "year is December 31, 2020", the message "Because it is the end of the year, the next day is January 1, 2021" is displayed, the year is incremented by 1, and the date is set to 1. It is a program to reset.
if year == 2020 and month == 12 and day == 31:
print("Since it is the end of the year, the next day is January 1, 2021")
year += 1
month = 1
day = 1
If the conditions are matched if you write as below, the message "Because it is the end of the year, the next day will be January 1, 2021" will be displayed, and the year will be +1 regardless of whether it matches or not, and it will be the month. The program will reset the day to 1.
if year == 2020 and month == 12 and day == 31:
print("Since it is the end of the year, the next day is January 1, 2021")
year += 1
month = 1
day = 1
By the way, I would like to make an Othello game right away, eh? Suddenly? No studying Python? You may think, but the way of studying here starts with learning based on what you have made. Aim to become a Python master while making Othello games! !!
As you all know, the Othello game is a board game in which the winner is the one who takes many positions using white and black pieces in the 8x8 squares.
Once you have created the logic of the Othello game, the program can be transformed into a communication battle game or a game with a good-looking graphic crunch, so here we will first create a simple CUI-based Othello game. Let's.
This time, I will use a development tool called PyCharm for programming. If you do not have it, please download and install PyCharm from the following site.
Download PyCharm from here >> Python IDE --PyCharm
The finished Othello game will be a text-based Othello game like this. It's simple, but it's an Othello game that you can play against each other, so let's make it together!
I made Othello to teach Python3 to children (2) >>
Recommended Posts