CodeGym /Courses /Python SELF EN /Working with PyCharm

Working with PyCharm

Python SELF EN
Level 3 , Lesson 3
Available

9.1 Creating Your First Program

Let's write our first program in Python. PyCharm has already prepped something for us, but hey, it wouldn’t be cool if our first program was someone else's code. So, let's delete it and write our own — even better.

Let's start simple – display some text on the screen. In Python, this is super easy – just write the command:


        print ("text")

That's it, you don't need to write anything else. No main() function, not even a semicolon like in other programming languages. Just the word print, brackets, and text in double quotes. These are not two single quotes – they're double quotes.

Feel free to put some fancy or dramatic text between the quotes – after all, it’s your first Python program. Here are 3 options you can choose from:

  • "The dark side offers me what the light cannot: true freedom."
  • "The dark side is a path to power that has no limits."
  • "I choose my destiny, and it is in darkness."

If you accidentally delete one of the quotes or type an extra one, PyCharm will highlight the line in red. For example:

In the example above, I accidentally deleted the closing double quote.

9.2 Running Your First Program

Now let's run the program and see what it outputs to the screen.

To run the program, click on the green triangle in the top menu. To the left of it, you'll see the name of the file that will start executing:

You can also run the program by pressing Shift+F10.

Let's do it, and you'll see your program's output in the console. Here's what mine printed:

The code written in orange – running the Python file main.py

The text highlighted in red is what my program output to the screen (in the console).

In yellow – service information stating that the program finished without errors.

9.3 Debugging

What happens if we make a mistake, how will Python react to it?

Let's delete the closing quote and run our program again. Here's what happened for me:

Python tried to execute the command (it's on line 2 for me), but it couldn't. This is what it says: SyntaxError: unterminated string literal (detected at line 2)

  • SyntaxError — syntax error [in the code].
  • unterminated string literal — incomplete string.
  • (detected at line 1) — error on line number 1.

As you're learning to code, mistakes are going to be your constant companions. But remember — only those who do nothing don't make mistakes.

You need to learn how to read errors correctly, understand what they're saying, and learn how to fix them.

9.4 What is the CodeGym Plugin and Why is it Needed?

This is an application, a special software module that integrates into the PyCharm development environment and allows you to work with CodeGym course tasks in it. For example, to write the solution code, send it for review, compare your solution with the "default" one, and much more. The progress in solving tasks in the plugin is synchronized with your account on CodeGym, so it will look the same both on the website and in the development environment.

You can download the CodeGym plugin from the Jetbrains marketplace, right in your development environment.

  1. Go to the "Settings" section, Windows/Linux File - Settings, MacOS PyCharm - Preferences. If there's no settings section, open any project or create a new one.

  2. In the window that appears, select the Plugins section in the sidebar and open the Marketplace tab. Enter codegym in the search bar.

  3. Select the plugin and click the Install button.
  4. Restart PyCharm (Restart IDE) to start working with the plugin.
  5. You will see a slightly changed interface and a Log in button on the upper horizontal panel.
  6. When clicked, a window will open for you to log into your account, where you need to enter your secret key:

    Remember, you can find your secret key in the “Settings” → “Security and Login” section.
    After logging in, the project and Codegym PY SDK will start loading (do not change to another version). It's built on Jetbrains Interpreter, Python version 3.12.
  7. To open a new task, click on Tasks in the left vertical panel, then on the task card in the sidebar on the left, and in the pop-up window click Open:

  8. A window with two tabs opened in front of you. One — with the task condition, the second — for entering code.
  9. Now type the solution to the task and click the Validate button.

Plugin installed! Now you can solve tasks.

Task Synchronization Site — Plugin

The task list and their statuses are updated automatically, every five minutes or after submitting any task for review (CodeGym server).

So if you’ve solved a task on the website, it will also be listed as solved in the plugin. If you need to update task statuses right away, click on your avatar (top right), and in the dropdown menu, choose Synchronize Tasks:

Beginner Mode in the Plugin

This is a simplified version for users with little to no experience working with PyCharm and other development environments. Some PyCharm functions are hidden. To disable this mode, click on your avatar (top right), and in the dropdown menu, choose Settings:

How to Hide the Plugin Navigation Panel in PRO Mode

Click on the Settings (⚙️) and uncheck the "Show Plugin Navigation Panel" option:

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION