[Python] Chapter 01-03 About Python (Write and execute a program using PyCharm)

[01-03] Write a program in PyCharm and execute it

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.

Program execution and interpreter settings in PyCharm

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. 2.png

Right-click the project name [python] of the project file you created on the desktop and select [New] → [Directory]. 1.png

Then create a folder there. This time it is ** chap01 **. 3.png

Right-click on [chap01] and select [New] → [Python File]. 4.png

Specify the program file name here. This time, for the sake of explanation, it is set to ** 01-03 **. 5.png

I will write the program in the red frame below. 6.png

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. 8.png

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.

Interpreter designation [first time only]

Explains how to specify an interpreter.

Click [Add Interpreter] in the following places to set the interpreter. 11.png

Click OK below. 11.png

The interpreter will be downloaded and installed. 12.png

The screen returns to the original program edit screen. The red frame below will disappear automatically after about 1 minute. 18.png 19.png

You have now installed the interpreter.

Program execution

Follow the steps below to ** right-click [01-03] and select ** → [Run '01-03'] to execute. 20.png

Then, the execution result will be displayed in the following places. 21.png

You can now run it from a file.

How to use the console in PyCharm

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. 22.png

You can see that the console screen appears. 23.png

At the ">>>" prompt below,

print(3+4)

Enter and press [Enter] to execute. 24.png

You should have confirmed that the above method can also be executed from the console.

Finally

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.

Return to [Table of Contents Link]

Recommended Posts

[Python] Chapter 01-03 About Python (Write and execute a program using PyCharm)
Let's write a Python program and run it
A little more about references ~ Using Python and Java as examples ~
Write a Caesar cipher program in Python
A story about Python pop and append
A program that plays rock-paper-scissors using Python
[Python] Chapter 02-04 Basics of Python Program (About Comments)
Create a web map using Python and GDAL
Create a Mac app using py2app and Python3! !!
A story about modifying Python and adding functions
[Python] A program that finds the minimum and maximum values without using methods
[Python] Chapter 01-01 About Python (First Python)
Write about building a Python environment for writing Qiita Qiita
Write a super simple molecular dynamics program in python
Try creating a compressed file using Python and zlib
Implementing a generator using Python> link> yield and next ()> yield
Read and write NFC tags in python using PaSoRi
A program to write Lattice Hinge with Rhinoceros with Python
How to execute a command using subprocess in Python
Using a Python program with fluentd's exec_filter Output Plugin
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
Using a python program with fluentd's exec Output Plugin
About python objects and classes
About Python variables and objects
Building a Python environment on a Mac and using Jupyter lab
What I learned about AI and machine learning using Python (4)
How to start the PC at a fixed time every morning and execute the python program
Read and write a file
About Python, len () and randint ()
[Treasure Data] [Python] Execute a query on Treasure Data using TD Client
About Python datetime and timezone
A memorandum about correlation [Python]
Write and read a file
A memorandum about Python mock
About Python and regular expressions
How to write a metaclass that supports both python2 and python3
Shoot time-lapse from a PC camera using Python and OpenCV
About Python and os operations
I made a Chatbot using LINE Messaging API and Python
Python # About reference and copy
About Python sort () and reverse ()
A note about [python] __debug__
Build a game leaderboard on Alibaba cloud using Python and Redis
Process Splunk execution results using Python and save to a file
Build a Python environment on your Mac with Anaconda and PyCharm
Create a simple scheduled batch using Docker's Python Image and parse-crontab
[Ev3dev] Create a program that captures the LCD (screen) using python
Try to write a program that abuses the program and sends 100 emails
[Python] I wrote a REST API using AWS API Gateway and Lambda.
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
Python a + = b and a = a + b are different
Write a binary search in Python
How to write a Python class
Python Note: About comparison using is
About installing Pwntools and Python2 series
I made a Line-bot using Python!
Authentication using tweepy-User authentication and application authentication (Python)
Python: A Note About Classes 1 "Abstract"
Drawing a silverstone curve using python
[Python] Let's write briefly about comprehensions
About python dict and sorted functions