ホーム 暮らし Introduction to Python with EduBlocks-1

Introduction to Python with EduBlocks-1

篠原 沙世 篠原 沙世 • 更新: • 公開: • 読了約 20 分
目次
n987c72759575

Hello everyone!
Today, I am bringing you the first installment of "Introduction to Python with EduBlocks."
When you hear the word programming, have you ever thought it seemed difficult because it's all in English?
Today, we will use a tool called "EduBlocks," which allows you to learn intuitively just by combining blocks like a puzzle.
Let's learn the basics together, such as displaying text, performing calculations, and using loops, in a fun way.
If you watch until the end, you will surely lose your fear of programming!

Let's check today's goals right away.
Today, there are four main objectives.
First, to be able to display text and numbers on the screen.
Next, to create a data container called a "variable" and perform simple calculations.
Furthermore, to understand the types of "arithmetic operators" such as addition and subtraction.
Finally, to master processing using a "for loop" that repeats the same action.
It might feel difficult at first, but don't worry, as I will explain everything carefully one by one.

First, let's talk about how to get started with EduBlocks.
Open your internet browser and access "app.edublocks.org" on the screen.
Once the screen appears, pay attention to the "Sign in" button in the top right corner.
If you register as a user and sign in here, you will be able to save the projects you create.
Once you have registered, click the "Python 3" button near the bottom of the screen to create a new project.

Next, we will look at how to create a project in detail.
When you click "Python 3," a "Create Project" screen will appear.
First, enter your preferred name for the project, such as "Ex-01," in the "Project Name" field.
What is important here is the "Type" setting below.
Please make sure that "Blocks," which is for beginners, is selected.
Finally, click the "Create" button in the bottom right, and the program editing screen will appear.


I will explain the blocks we just used in detail.
The "print" block is very useful when you want to display something on the screen.
This is the most basic output function in Python.
For example, if you place the block "print("Hello World-1")", the text will be displayed as is.
When you want to display the number "1," you use "print(1)."
The rule is that text must be enclosed in symbols called double quotes, but the point is that numbers can be used as they are without being enclosed.
"

Next is about "variables."
What comes to mind when you hear the word variable?
It sounds difficult, but it is actually like a "box" for storing data.
Select "Variables" from the menu on the left and click "Create variable..."
Let's name it "A" here.
Then, a block that says "A = 0" will appear.
This means "I put the number 0 into a box named A."
Creating this box is very convenient because you can use it for calculations later.


Now, let's actually use the variables we created to perform calculations.
For example, by setting "A = 10" and "B = 20," we put 10 into box A and 20 into box B.
Next, we create a block that says "print( A + B )."
When you run this, the computer takes the 10 inside box A and the 20 inside box B and adds them together.
The calculation result, "30," will be displayed in the console.
You can also see that just by arranging the blocks, the actual Python code is being created automatically in the background.

Example of variable usage/video


What is important here is "how to combine text and numbers."
Even if only the calculation result "30" is displayed, it is hard to tell what that number represents, right?
So, let's display the text "A+B=" together with the actual calculation result.
Use the "+" or "-" buttons inside the print block to increase the fields and separate them with commas.
Then, you can display it as an easy-to-understand sentence like "A+B= 30."
Please make sure to remember this technique of combining text blocks and variable blocks.

Next, I will introduce the symbols used for calculations, called "arithmetic operators."
We used "+" for addition earlier, but there are various other symbols as well.
We use "-" for subtraction, the asterisk "" for multiplication, and the slash "/" for division.
Furthermore, there are symbols like "%" for the remainder of a division, "//" for integer division, and "" for exponentiation.
These are all gathered in the "Math" menu, so please try out various calculation blocks as if you were using a calculator.

Let's delve a little deeper into the concept of "assignment" here.
In the world of programming, "=" (equals) does not mean "is equal to," but rather "put the thing on the right into the box on the left."
For example, if you set "A = 0" and then "A = 1," the content of box A is overwritten from 0 to 1.
If you set "A = 2," it becomes 2.
If you display these in order using print, you can see the content changing from 0 to 1 to 2.
Remember that the contents of the box can be replaced with new data at any time.

There are magic symbols that make the assignment we just discussed even more convenient.
These are compound assignment operators like "+=".
For example, if you write "A += 1," it means "add 1 to the current content of box A and put it back into box A."
In other words, if A is 0, it becomes 1; if it is 1, it becomes 2.
Similarly, "-=" performs subtraction before assignment, and "
=" performs multiplication before assignment.
It might feel a bit difficult, but this is a very practical technique frequently used when adding up scores in games.

Compound assignment operators include plus-equals.
In addition to minus-equals.
There is multiply-equals for multiplication and assignment.
There is slash-equals for division and assignment.
There is also percent-equals for modulo and assignment.

Have you ever thought it was tedious to manually repeat the same task over and over?
With programming, you can solve it in an instant using a "for loop."
Bring the "for i in range(10)" block from "Loops" in the menu on the left.
This is an instruction that says, "Repeat the commands in the blocks placed inside here 10 times."
Just by putting "print("Hello World")" inside this, "Hello World" will be displayed 10 times in a row.
The computer will repeat it as many times as you want without complaining.

Repetition (for block) / Creation video


Let's organize the mechanism of the program we just ran.
The initial "import time" is a signal to prepare a special toolkit for manipulating time.
"for i in range(10)" is a loop that repeats 10 times, and each time it loops, numbers from 0 to 9 are sequentially put into the variable "i."
"print(i)" displays that number, and "time.sleep(1)" pauses the program for 1 second.
The real thrill of programming is being able to create intended movements by combining multiple commands in order like this.

How was it?
Here is a summary of today.
The biggest feature of EduBlocks is that the blocks and Python code correspond "one-to-one."
Just by assembling blocks, you naturally acquire the basic structure of programming.
While it is easy to use because it runs entirely in a browser, you can also challenge yourself with advanced tasks like data aggregation and graph drawing.
The basics you learned today will be a powerful bridge when you perform data analysis in the future.
Let's continue to learn together in a fun way!
Thank you for watching until the end.



同じカテゴリの記事

篠原 沙世

アニメとゲームの新作情報を担当。制作会社・配信元の公式告知と登壇情報を照合して記事化します。

おすすめの関連記事