Persisting and Sharing Data

Working in a Programming Environment


Learning Objectives

  • You can distinguish the editor, the Python interpreter, and the terminal.
  • You can open a project folder, edit and save a Python file, and run the program and its checks from the editor’s terminal.
  • You can find the file and line named in an error message.
  • You can download an exercise and submit local files through the IDE plugin or a ZIP upload.

So far, the course editor has supplied a place to write and run Python. You can also do that work on your own computer. This becomes useful when a program has several source files and data that should remain available after the program ends.

We will set up an editor, run one small file, and check its result. The course’s browser editor remains available while you set up the local environment.

The Editor and Python Have Different Jobs

An integrated development environment, or IDE, brings editing and development tools together. VSCodium is an editor that can serve this role. Its file explorer shows your project, its editor changes source files, and its integrated terminal runs commands.

The Python interpreter executes Python code. Installing an editor does not necessarily install Python. The terminal is where you enter commands such as python practice.py; it is different from the source file you are editing.

Install an Editor

Download VSCodium for your operating system and follow its installation instructions. If you already have a suitable editor, you can use it with the same files and terminal commands.

Open the editor after installation. The first practice steps use its integrated terminal. Later in this chapter, we will add the course plugin to download and submit exercises.

Check or Install Python

In VSCodium, select Terminal → New Terminal. Try the command for your operating system:

SystemCommand to check Python
Windowspy --version
macOS or Linuxpython3 --version

A result beginning with Python 3. shows that the command can find Python. Use a currently supported Python release, version 3.11 or newer: the Pyxel game later in this part requires at least 3.11. If the command is not found or reports an older version, follow the relevant official guide:

After installing, close and reopen the editor and its terminal, then check the version again. If your working command is python instead, use that command consistently below. The command name can differ; the file contains the same Python.

Commands Belong in the Terminal

Do not put py --version or python3 practice.py into a Python source file. Type terminal commands after the terminal’s prompt.

If the prompt is >>>, you have entered Python’s interactive interpreter. Type exit() to return to the terminal before running a file command.

Open a Folder and Create a File

Create a folder named programming-practice in a location where you keep your own documents. In VSCodium, use File → Open Folder to open that folder.

Use the file explorer’s New File action to create practice.py. Check the complete filename: it should end in .py, not .py.txt.

Write:

print("Hello from my own computer!")

Save the file with File → Save, Ctrl+S on Windows or Linux, or Command+S on macOS. The editor holds your current text; saving updates the file that Python will read.

Open a new terminal after opening the folder. Check that its current folder is programming-practice. The command dir on Windows or ls on macOS/Linux should list practice.py.

Run the Saved File

In that terminal, run one of these commands:

py practice.py

on Windows, or:

python3 practice.py

on macOS/Linux. You should see:

Hello from my own computer!

Change the message, save, and run the same command again. Predict which message will appear. If the old message appears, check that you saved the file and are running the file in the folder you opened.

The terminal’s current folder matters when a program uses a relative path. Opening a source file in an editor does not itself change a terminal’s current folder. The next chapter examines paths in more detail.

Test a Small Function

Replace the contents of practice.py with a function and checks for its contract. Assume total and answered are nonnegative integers, with answered no larger than total.

def remaining_words(total, answered):
return total - answered
assert remaining_words(3, 1) == 2
assert remaining_words(3, 3) == 0
assert remaining_words(0, 0) == 0
print("Checks passed.")

Save and run the file. Successful assertions print nothing, so the final line tells you all three checks were reached and passed.

Change the function to return total + answered, leaving the expectations unchanged. Save and run again. The first assertion should fail with AssertionError. Read the last line of the traceback, then find the filename and line number above it. The editor shows line numbers beside your code.

Restore subtraction and run the checks again. This time the expectations should pass. A failed check is evidence to investigate; changing an expected result merely to hide a bug would lose that evidence.

Keep a Repeatable Working Routine

For each small change:

  1. Read the requirement and predict one result.
  2. Edit the relevant file and save it.
  3. Run the program or check file from the project folder.
  4. Compare the result with the prediction.
  5. Add a boundary case before moving to the next change.

Later exercises supply check.py or another named check file. Run it with the same Python command, for example python3 check.py. The imports chapter will show how a check file uses functions defined in another source file.

Local checks help you investigate your work. They are separate from submitting an exercise for the course’s grading feedback.

Install the Aalto OpenCS IDE Plugin

Aalto OpenCS IDE lets you download exercises, submit local files, and read grading feedback from your editor.

In VSCodium, download the aalto-opencs-ide…vsix file under Assets on the latest release page. Open View → Extensions, select … → Install from VSIX…, and choose that file. VSCodium uses a different extension catalog from the Visual Studio Marketplace, so we use this installation route.

If you use Visual Studio Code, open View → Extensions, search for aalto-opencs.aalto-opencs-ide, and install Aalto OpenCS IDE, published by Aalto University OpenCS.

Reload the editor if prompted, then open the Aalto OpenCS icon in the Activity Bar beside the sidebar.

Sign In and Download an Exercise

  1. Select Sign In with Browser and sign in with the same OpenCS account you use for this course. Allow the browser to reopen your editor; use open it manually if needed.
  2. Select Choose Assignment Folder and choose programming-practice. The plugin creates exercise folders inside it.
  3. Select Select Course, then choose the course and version you are studying. If it is missing, check your enrolment in the browser and refresh the course list.
  4. Under Course Parts, expand Part 5 and select Submit a local practice program, the exercise below.
  5. Select Download Exercise, then Show Handout to read the instructions. Work in the downloaded main.py.

Keep using that downloaded copy when you return. Redownload Assignment replaces it with fresh starter files.

Work Locally and Submit

Complete practice_summary(total, answered) as described in the handout. Keep the supplied assertions and add one of your own.

Save the file. Open the downloaded exercise’s folder with File → Open Folder, then choose Terminal → New Terminal. Check with dir or ls that the folder contains main.py. Run:

  • Windows: py main.py
  • macOS/Linux: python3 main.py

Use python instead if that was your working command earlier. Successful checks print Checks passed.. If an assertion fails, read the traceback, fix the function, save, and run again. When available, the plugin’s Run Current Exercise runs the same file for you.

To submit through the plugin:

  1. Save your changes and check that Submit a local practice program is the selected exercise.
  2. Choose Submit Current Exercise in the Exercise view.
  3. Review the file list: it should contain main.py. Confirm with Submit.
  4. Wait for grading in Submissions and read the feedback. Fix and resubmit if needed.

Local checks do not award points; submitting sends your solution for grading. Refresh this course page to see the recorded result.

Alternatively, Submit a ZIP

You can also download the exercise using Download starter code below. Extract starter.zip into its own folder inside programming-practice, then edit and test main.py as above. If you already solved it through the plugin, use that file.

Create submission.zip with main.py directly at its top level, without an enclosing folder. Use your file manager, or run one of these commands in the exercise folder:

SystemCommand
Windowspy -m zipfile -c submission.zip main.py
macOS/Linuxpython3 -m zipfile -c submission.zip main.py

Choose the ZIP in the upload area below, press Submit, and read the grading feedback. Both routes submit to the same exercise; you only need one.

Submit a local practice program

0 / 5 points

Download this exercise and solve it in your IDE. Use the Aalto OpenCS plugin’s Download Exercise functionality. Alternatively, you may use Download starter code below and extract the ZIP into a separate folder.

Complete practice_summary(total, answered) in main.py. The arguments are integers with 0 <= answered <= total. Return a string with exactly this format: "Answered: 2, remaining: 3" for total=5 and answered=2. The remaining count is total minus answered. Include the capitalization, comma, and spaces shown; do not include a newline. The function returns the string without printing or asking for input. You do not need to validate arguments outside the stated range.

Examples:

CallReturned string
practice_summary(5, 2)"Answered: 2, remaining: 3"
practice_summary(4, 4)"Answered: 4, remaining: 0"
practice_summary(0, 0)"Answered: 0, remaining: 0"

Keep the supplied checks below the function. Add one assertion with a different valid pair of arguments before the final print. Save the file and run py main.py on Windows or python3 main.py on macOS/Linux, using python if that is your working command. You should see Checks passed. when all sample assertions pass. The grader also checks other valid inputs.

Submit through either route:

  • IDE: select this downloaded exercise, choose Submit Current Exercise, check that the file list contains main.py, and confirm Submit.
  • ZIP: create submission.zip containing main.py at the archive’s top level, choose it in the upload area below, and press Submit. Include the file itself, without an enclosing exercise folder.

From this exercise folder, create the ZIP with py -m zipfile -c submission.zip main.py on Windows or python3 -m zipfile -c submission.zip main.py on macOS/Linux.

Submit only this exercise’s main.py, including its function and checks. Do not submit the earlier practice.py or the whole programming-practice folder. Wait for the grading result and read its feedback; running local assertions alone does not submit the exercise.

Use This Workflow in Later Exercises

The later file exercises use the same download, edit, test, and submit workflow. Open each exercise in its own folder. Many supply main.py for your functions, check.py for assertions, and sample data files. Follow the handout: running main.py may only define functions, while py check.py or python3 check.py actually calls and tests them.

Use the file list and ZIP command in that exercise’s handout. Include all of its required source and support files at the archive’s top level. Generated reports, personal game history, .venv, and __pycache__ stay on your computer. Read the grading feedback after submitting through either route.

Check Your Understanding

  1. What roles do the editor, Python interpreter, and terminal have when you edit and run a program?
  2. How can you check whether the terminal is in the intended project folder?
  3. What should you investigate when an assertion fails?
  4. How does running local checks differ from submitting for grading?

The next chapter uses this same edit, save, run, and check cycle with text files. On your computer, files you create in the practice folder remain there between runs.