Until now, programs have been run on the console. This time, I would like to see how to write a program in a text editor and write the execution result of it in the console.
As explained in the previous "01-02", the program can be executed in the following ways.
--How to use the interactive command line (interpreter format) as if you were entering a command --How to write a program and run it
This time, I would like to explain the latter, "how to write and execute a program".
First of all, as I explained last time, when you start PyCharm, the following screen will appear.
Right-click the project name [python] of the project file you created on the desktop and select [New] → [Directory].
Then create a folder there. This time it is ** chap01 **.
Right-click on [chap01] and select [New] → [Python File].
Specify the program file name here. This time, for the sake of explanation, it is set to ** 01-03 **.
I will write the program in the red frame below.
Please enter the following program. (Detailed explanation will be described later.)
01-03.py
a = 15
b = 10
print(a+b)
When I write a program, I execute it, but when I execute it, I need to specify an interpreter. (First time only) You may be getting the following error.
Since no interpreter is specified in this state, the program cannot be executed as it is. A ** interpreter ** is a program that executes code written in a programming language while interpreting it at any time.
Explains how to specify an interpreter.
Click [Add Interpreter] in the following places to set the interpreter.
Click OK below.
The interpreter will be downloaded and installed.
The screen returns to the original program edit screen. The red frame below will disappear automatically after about 1 minute.
You have now installed the interpreter.
Follow the steps below to ** right-click [01-03] and select ** → [Run '01-03'] to execute.
Then, the execution result will be displayed in the following places.
You can now run it from a file.
In [01-02], I wrote a program like a command from the console and executed it. You can do the same on PyCharm. Select Tools> Python or Debug Console as shown below.
You can see that the console screen appears.
At the ">>>" prompt below,
print(3+4)
Enter and press [Enter] to execute.
You should have confirmed that the above method can also be executed from the console.
In this way, you can also write it in Pycharm and then check the result on the execution screen. Now that you've learned two methods, you'll actually use both. This section is a basic part, so please hold it down. Next time, from Chapter 2, I would like to get into the actual contents of the program.
Recommended Posts