On this page:
- PyCharm Edu basics
- Creating a course
- Creating the first lesson
- Writing a task text
- Writing an exercise code for a task
- Creating answer placeholders
- Previewing a task
- Executing your exercise code
- Writing tests for a task
- Wrapping everything
- Creating the course archive to share it with students
- Quick creation of educational course
- From the student’s viewpoint...
- Publishing a course to Stepik
This guide is intended for the educators who want to create their courses and assignments with PyCharm Edu. You will learn how to create a course, add lessons and tasks, write exercise code and tests for a task, how to pack your project into a course archive and upload this archive to be shared with the students.
Note: PyCharm Edu runs on Windows, Linux and Mac platforms. We used Windows to prepare this guide. On Linux and Mac some menu names or workflows may slightly differ.
PyCharm Edu basics
A course is just a project of a special type. It consists of lessons.
- Task description which you have to type in the Task Description tool window
- The file with the extension
.py, that contains the exercise code and can contain answer placeholders
- the test file
tests.pythat helps you make sure that the students have fulfilled your task correctly.
Also a task can contain more files required for fulfilling it.
- Answer placeholder
An answer placeholder is a frame shown to the students that replaces and hides a part of your initial code. These placeholders should contain descriptions of actions to be taken by the students to complete the tasks. You have to create descriptions of these actions yourself.
The first mouse click inside the answer placeholder selects the entire placeholder; the second mouse click removes selection.
Make sure that the following prerequisites are met:
- You are working with the latest version of PyCharm Edu.
- You have a Python interpreter properly installed on your computer. Refer to the section Configuring Python SDK for details.
You can opt to install the Anaconda or Canopy libraries, which include the superset of the scientific stack comprising most of the mentioned libraries as recommended by Google engineers. Note that the libraries are really huge!
For this particular course the following packages are required:
Creating a course
You can create a project in two possible ways: either from the Welcome screen, or by choosing File | New Project... on the main menu. Refer to the section Creating Projects from Scratch in PyCharm Edu for details.
In the New Project dialog, choose the project type Course creation. You are suggested to specify the location of your course project, the Python interpreter that will be used for your course, the name of your course, and its description. Note that the availability of the Python interpreter depends on your platform. When ready, click Create:
The project for the first educational course is ready.
What’s inside this project?
As you see in the Project view, PyCharm Edu has created some infrastructure:
There is one top-level node in the Project tool window:
PyCharmTutorialCourse . If you expand it, the nested elements become
- Under the number 1 (PyCharmTutorialCourse), you see the files and folders pertaining to your new project.
As you can see, there is not so much so far…
- The folder
lesson1denoted with the icon . This folder contains two stub files:
tests.py. These files are color-coded: the black file is visible to the students (task.py), and the grey file (tests.py) is not visible to them.
- The file
test_helper.pyis a library of auxiliary functions, which help you write custom checks and tests for your tasks. This file is grey.
- The folder
- The opened Task Description tool window. It features the toolbar with the icons that allow
you to check the task execution (), move between tasks (), refresh task (), view hints
(), and edit tasks ().
Note the following:
1) these actions are available to the students.
- There is the now empty space, which will be occupied by the editor - if you press F4 on a file in the Project tool window, its content will appear in a separate tab in the editor.
Why do we need a Python interpreter at all? You will write programs in Python, that’s why an interpreter is mandatory.
Refer to the section Configuring Python SDK for details.
Note that different versions of Python have different syntax and features. For example, Python 2.x and Python 3.x significantly differ from each other. That’s why the students should refer to the same interpreter that was used in the course. However, there are no rigid rules. A student may successfully use Python 3.3, while the lecturer in his/her course may use Python 3.4.
Creating the first lesson
Now it’s time to flesh out the project.
In the Project tool window, select
lesson1 and press
Shift+F6. In the dialog box that opens, type the new name of the lesson (here it is
Basics), and then click OK:
Thus, you've performed the rename refactoring.
Next, let's rename the task
task1 of the
To do that, click this task and press Shift+F6:
Next, let's add an image file that should be read. PyCharm Edu makes importing such a file quite easy - just drag it to the Project tool window, and then specify the target directory in the Move dialog:
Writing a task text
<html> Write your task text here. <br> </html>
(Note that you can also use Markdown to write your description… The language is configured in the page Tools | Education of the Settings/Preferences dialog.)
Instead of the existing text, type the following:
<html> Use <b>imread</b> function to load PyCharm Edu logo and play with it a little bit. <br> </html>
To see this text as it will be viewed by the students, just release the button .
Writing an exercise code for a task
Why do we need to write an exercise code? An exercise code is a part of a task. Some fragments of this exercise code will be replaced with the answer placeholders, which we'll create later. The students, when performing a task, will have to fill in these fragments with their own code.
For example, we are going to create a console application that reads an image file. To fulfil this example, open
for editing the
read_images.py file (F4), and
type the exercise code:
from skimage import io image_name = "PyCharm.png" img = io.imread(image_name) print(img.shape) img_gray = io.imread(image_name, as_grey=True) print(img_gray.shape)
Creating answer placeholders
Now that we have the answer, we need to define the question, i.e. what the student has to actually do to get to that answer. PyCharm Edu suggests so called answer placeholder — frames, that will replace some parts of your original exercise code, where the students will have to write their solutions.
These answer placeholders are created easily:
- Select a fragment of your exercise code you’d like to replace with some text. In our case, these are the
- Right-click selection, and on the context menu, choose : PyCharm Edu shows the Add Answer Placeholder dialog box.
- Use this dialog box to specify the text that will replace the selected fragment in the students’ project. If you want to show a prompt to your students, or a theoretical help for the specific answer placeholders, If you want to show a prompt to your students, or a theoretical help for the specific answer placeholder, just type the hint text. If you want to add more hints, click :
- Click OK when ready.
That’s it! The task with a question is ready. If you now open the context menu of the answer placeholder in question, you will notice three more menu items: Edit Answer Placeholder, Delete Answer Placeholder and Delete All Answer Placeholders, which are quite self-explanatory.
Previewing a task
You would probably like to see how your task will be viewed by your students. To do that, right-click the task
file in the Project tool window,
and choose on the context menu.
In the example we are working on, right-click the file
PyCharm Edu immediately opens in the editor the file
read_images.py, as it will be seen
by the students:
Note that actually the file
read_images.py is temporary. It does not appear in the
Project view of the Project tool window. As soon as you close this file, it just
Executing your exercise code
Just to make sure that everything has been done correctly, you’d probably need to run your exercise code and check that it works properly and solves the task you’ve created.
So, click in the left gutter. It is the same as if you run your program with the default run/debug configuration.
After clicking , PyCharm Edu shows the expected result - console with the program output.
Writing tests for a task
The fragments of the exercise code which you replace with answer placeholders are not intended to verify the
student’s input. The actual checks are accomplished by the tests that should be placed in the files
tests.py, available for each task. These tests help you make sure that the students
have completed your task in the way you've specified.
- All tests for a task should be written in the file
tests.py, located under each task in the Project view.
- A test file
tests.pyis created automatically, when you create a task. Such file already has some predefined common tests. Modify this file by adding your custom tests to check the students’ solutions.
tests.pyfor a task is launched in the background when a student clicks .
- You can write your custom tests using PyCharm Edu testing framework. The file
test_helper.py, located inside each course project, contains useful functions, which you can use to write your own custom tests. Let’s explore some of these functions.
- First, you have to make use of the functions
passed(), which print test results in a legible and parsable format. You can pass a string to the function
failed()- this string will be shown as an error message to a student who failed to execute a task properly.
- Second, as mentioned earlier, a typical test is created automatically. It contains calls to the base tests
run_common_tests. These common tests make sure that a file does not contain syntactical errors, is not empty, that a user did not just delete the contents of a task window, but changed something.
test_helper.pycontains a handy function
get_answer_placeholders()that returns a list of answer placeholders filled in by a student. Try to access the first answer placeholder
To do that, write the following code in the file
placeholders = get_answer_placeholders() placeholder = placeholders
Rather simple, isn’t it?
- First, you have to make use of the functions
- Explore the file
test_helper.pyfor the other useful functions.
Writing a test
Open a file
tests.py for editing (select this file in the Project tool window, and
press F4). The following code opens in the editor:
from test_helper import run_common_tests, failed, passed, get_answer_placeholders def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders if placeholder == "": # TODO: your condition here passed() else: failed() if __name__ == '__main__': run_common_tests() # test_answer_placeholders() # TODO: uncomment test call
Then change this file as required. For example, the test file checking the first task window will look like the following:
from test_helper import run_common_tests, failed, passed, get_answer_placeholders from test_helper import import_task_file def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders if placeholder == "io.imread": passed() else: failed("Try to use imread() function from io module") task_file = import_task_file() if task_file.image_name == "PyCharm.png": passed() else: failed("PyCharm logo filename is incorrect") if __name__ == '__main__': run_common_tests() test_answer_placeholders()
Check your tests and exercise code
OK, let's try to execute exercise code and tests for our example.
To run the exercise code, open the file
read_images.py for editing
(F4), and in the Task Description tool window click the button
. Results show as the popup (Congrats or Failed) above the button, and in the
Run tool window.
This action allows seeing run results as the students see them.
To run tests for
read_images.py, click in the left gutter of the file
tests.py. PyCharm Edu shows the test output in the Run tool window:
All tests passed, because our exercise code was a correct solution.
PyCharm.png to something else in your exercise code
read_images.py and try to re-run the tests. This time the result is different.
Creating the second task
Next, let's create the other task in the lesson
Basic. To do that, click
this lesson in the Project tool window, and press Alt+Insert.
The new task is created under the lesson
Basic. Note that a task consists of
the following files:
The task’s files immediately open in the editor. However, before proceeding, let's rename the file
task.py. To do that, click this file in the Project tool window, press
Shift+F6 and specify the new name (here
All the task files already have some pre-defined contents. However, we have to edit them in order to produce something meaningful.
Writing contents of the second task
- Enter the following text in the Task Description tool window:
<html> Load picture with coffee and save it to the proper file. </html>
- Open the file
write_image.pyfor editing and enter the following code:
from skimage import io from skimage import data coffee = data.coffee() filename = "coffee.png" io.imsave(filename, coffee)
- In the file
write_image.py, create the task window. To do that, select the piece of code
filename, coffeeand choose from the context menu of the selection.
- In the Add Answer Placeholder dialog, write the text that will be shown to the students, and the hint:
- Open for editing the file
tests.py. It already contains some predefined code. Change this code as follows:
import filecmp import os import sys from test_helper import run_common_tests, failed, passed def match_pictures(): answer_path = os.path.join(sys.argv, "coffee-answer.png") if filecmp.cmp("coffee.png", answer_path): passed() else: failed("Hey! It's a mistake!") if __name__ == '__main__': run_common_tests() match_pictures()
- Add the image file
coffee-answer.pngto the root of the project.
- Run the test. To do that, click in the left gutter of the task file
Creating another lesson and the nested tasks
Next, let's create another lesson. To do that, in the Project tool window, press Alt+Insert and choose the option Lesson:
Next, to prepare for running, do the following:
- In the Project tool window, select the lesson
Advanced, and press Alt+Insert again to create a new task named
Let's swirl PyCharm.
- Rename the file
swirl_pycharm.py(Shift+F6), open it for editing (F4) and type the following code:
from skimage import io from skimage.transform import swirl image_name = "PyCharm.png" img = io.imread(image_name) swirled = swirl(img, rotation=0, strength=20, radius=120, order=2) io.imsave("swirled.png", swirled) swirled2 = swirl(img, rotation=0, strength=20, radius=120, order=2) io.imsave("swirled2.png", swirled2)
This code reads the file
PyCharm.png, and then creates two "swirled" files
- Then, add the answer placeholder to the code
rotation=0, strength=20, radius=120, order=2of the statement
swirled2 = swirl(img, rotation=0, strength=20, radius=120, order=2)with the text “Сhoose your parameters”.
- Add the image
PyCharm.pngto the root of the task
Let's swirl PyCharm.
- Add new contents to the file
from test_helper import run_common_tests, failed, passed, get_answer_placeholders def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders if "=" in placeholder: passed() else: failed("play") if __name__ == '__main__': run_common_tests() test_answer_placeholders()
- Write the task text in the Task Description tool window ():
<html> Use <b>imread</b> function to load PyCharm logo and play with it a little bit. </br> Find more information <a href="http://scikit-image.org/docs/dev/auto_examples/plot_swirl.html">here</a> </html>
Finally, run the file
swirl_pycharm.py and its test (click in the left
This time, when you look at the Project tool window, you see the two files:
These files appear as the result of executing the code in the file
And to round up, create one more task under the lesson
Advanced. Let it be the
Overview with the following files:
Overview.txtwith the following text:
Hope you enjoyed our tutorial! Create your own courses and have fun!
Creating the course archive to share it with students
OK, your first course is ready. What’s next?
- Right-click anywhere in the Project tool window and choose Course Creator | Generate Course Archive:
- Type the archive name and location (or accept defaults) in the dialog box that opens:
View the archive file
PyCharmTutorialCourse.zipwith the actual course archive in the Project tool window:
Students can use
PyCharmTutorialCourse.zipto go through your course!
Quick creation of educational course
PyCharm Edu provides an action that allows you to quickly create a students’ course from the current educators’ course. This action is called Preview Course, and it’s invoked from the Course Creator node:
From the student’s viewpoint...
To make sure that everything has been done properly, create a new educational project ().
Click Create. The new educational project opens. Note that the texts of your tasks
now show in the Task Description tool window, and the files
contain the task windows hiding the correct solution.
The rest is left to the students. They have to fill in the task windows to fulfil the task, leaving you with the job to check whether they were right in their guesses.
Publishing a course to Stepik
We encourage you to make your course available publicly for other educators and students. In order to publish it to Stepik, you need to create you own account.
PyCharm Edu saves these credentials in the Education page of the Settings/Preferences dialog.
That's it, folks... Congrats! You've created you first educational course.