Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JCA Python - Middle v. 2021 Lesson 01 Foxit

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Lesson 1

INTRODUCTION
TO PYCHARM AND
DEBUGGER

Contents
Introduction to PyCharm................................................3
Debugger.......................................................................... 9

This lesson uses videos that have a PLAY icon over the
illustration. Click on it to watch the video.
For correct displaying the videos, we recommend opening the
lesson in the Foxit PDF Reader.

2
Introduction to PyCharm and Debugger

Introduction to PyCharm
So, you have installed PyCharm, a powerful IDE
(Integrated Development Environment).
This is a professional tool for much more convenient
work with code because it includes the following functions:
■■ text editor significantly increases the comfort of writing
code, and it highlights possible errors;
■■ library configuration automation allows you to install the
necessary libraries automatically;
■■ Debugger allows you to work with the program and identify
errors step by step.
Therefore, we will rather move on to project creation.
Click on the New Project button, and a window will
open like in Figure 1:

Figure 1

3
Lesson 1

It would help if you chose the path where the project will
be stored. It would help if you chose the virtualenv (virtu-
al environment) in the New environment using item and
placed it in the project directory, naming venv or .venv.
As a Base interpreter, choose the one that PyCharm
suggests.
For lack of guidance, ask your instructor to set Python
working.
Remove the checkmark from the Create a main.py
welcome script item.
The settings window should look like in Figure 2:

Figure 2

After filling in all the items, press the Create button.

4
Introduction to PyCharm and Debugger

The created project is loaded, and we enter in the main de-


velopment window (Figure 3):

Figure 3

We see the project structure in the upper left part, where


there is only one directory with the name we set while the
virtual environment is created. This directory contains the
Python interpreter, which executes the code. But where did
it come from?
The fact is that the same Python interpreter was installed
on your system when setting up the software, and when cre-
ating the project, PyCharm took it as a basis and created a
copy, placing it inside the project (Figure 4).

5
Lesson 1

Figure 4

And why are such complications needed if we can use


the system interpreter?
Each project uses different libraries; therefore, the num-
ber of libraries will go off the scale with many projects. Most
of them will not be needed for a particular project. Thus, the
virtual environments are created with local interpreters con-
taining libraries and modules required for the operation of a
specific project to preserve the purity of the system and the
project (Figure 5).
Right click on the project directory, and create a new one
Python File entitled the main.py (Video 1).

6
Introduction to PyCharm and Debugger

Figure 5

Video 1

7
Lesson 1

The created file is opened, and you can work with it. The
window looks like in Figure 6:

Figure 6

Do you remember your first program that outputs the


string “Hello World!”? Let’s create a similar one in a
new software environment.
We will write in the central column a familiar command,
then right-click on a space, and select Run (Video 2).

Video 2

8
Introduction to PyCharm and Debugger

As you can see, a window with a console appeared, where


the result was displayed.

Debugger
We have recalled the first program, so let’s remember
the turtle graphics using the for loop, of course.
Erase everything and write the code to draw the wheel:

from turtle import *


shape("turtle")
pensize(8)
color("orange")
for i in range(10):
forward(100)
left(180)
forward(100)
left(180)
left(36)
penup()
right(90)
forward(100)
left(90)
color("brown")
pendown()
pensize(15)

9
Lesson 1

You need to click on the green triangle in the upper right


corner to run the code (Figure 7).

Figure 7

We will get the result like in Video 3:

Video 3

You see, the turtle drew the wheel quickly and disap-
peared, making it impossible to know the result of the
10
Introduction to PyCharm and Debugger

work. In addition, the code is quite difficult to read, and we


would like to see how it works step by step. We will use the
Debugger for this.
But first, you need to put a breakpoint, from which we
will begin to implement the code step by step. As the turtle
starts to move in the for loop, we will set the breakpoint at
its beginning. Hover the cursor between the code and the
string number, and click the left mouse button.
See Video 4:

Video 4

11
Lesson 1

You can start the Debugger by clicking on the beetle


icon in the upper right corner or through the context
menu invoked by right-clicking on an empty field of the file
(Figure 8).

Figure 8

A window with a turtle appeared (Figure 9).

Figure 9

At the same time, a debug window appeared in the


working window (Figure 10), where the process control is in
progress.
12
Introduction to PyCharm and Debugger

Figure 10

It is a powerful tool with many functions, but we need


only the ones shown in Figure 11:

Figure 11

13
Lesson 1

1 Stops the program.


2 By pressing this button, the program will continue to
run until the next stop point (Video 5).

Video 5

3 Re-starts the debugging process (see Video 6 on page


15).
4 Console, which displays the results of the program
during debugging.
5 Go to the next step in the code (Video 7).
6 The field where the values of the variables are displayed.

14
Introduction to PyCharm and Debugger

Video 6

Video 7

15
Lesson 1

Today we have got acquainted with the PyCharm, one of


the best Python IDEs, and we have learned how to create
virtual environments for our professional projects.
Also, we have got practical skills in debugging code us-
ing Debugger.
And we will use these powerful tools to create exciting
and entertaining programs in your following lessons.

16
Introduction to PyCharm and Debugger

17
Lesson 1
INTRODUCTION TO PYCHARM
AND DEBUGGER

© STEP IT Academy
www.itstep.org

All rights to protected pictures, audio, and video belong to their authors or legal owners.
Fragments of works are used exclusively in illustration purposes to the extent justified by
the purpose as part of an educational process and for educational purposes in accordance
with Article 1273 Sec. 4 of the Civil Code of the Russian Federation and Articles 21 and 23
of the Law of Ukraine “On Copyright and Related Rights”. The extent and method of cited
works are in conformity with the standards, do not conflict with a normal exploitation of
the work, and do not prejudice the legitimate interests of the authors and rightholders.
Cited fragments of works can be replaced with alternative, non-protected analogs, and
as such correspond the criteria of fair use.
All rights reserved. Any reproduction, in whole or in part, is prohibited. Agreement of the
use of works and their fragments is carried out with the authors and other right owners.
Materials from this document can be used only with resource link.
Liability for unauthorized copying and commercial use of materials is defined according
to the current legislation of Ukraine.

You might also like