Skip to content

PythonCode Documentation

Getting started

  • In your browser, go to the URL: https://pythoncode.eecs.yorku.ca. Login with Your Passport York or EECS Credentials.

  • For a quick introduction to Simple mode, view the video: PythonCode Simple Mode. (Use 1080P/HD for best quality).

    • A manual is available at the PythonCode Documentation.
    • It is best to obtain EECS credentials (login/password). The process is simple at Obtain EECS credentials. You will need your student number. PythonCode allows you to self-grade your work with Unit Tests, but to submit your work easily, obtain and EECS account.
    • See also the PythonCode Wiki for more on this EECS project.

What is PythonCode?

PythonCode: a Python IDE in the browser for online student engagement.

This project has the goal of providing a “lightweight” IDE in the browser for snippets of Python code or small projects. It would not support all the features of an industrial strength IDE, but would allow students to try a snippet of code in class or online on their browsers (laptops and tablets).

The PythonCode webbapp also supports:

  • Type annotations and static type checking of Python code using a tool called mypy.
  • Unit Testing using a a tool called pytest.
  • Using pytest, a student may also grade themselves to check the correctness of their code (and submit the code if the the instructor has set this up).
  • PythonCode can also be used for labs or tutorials involving plots. See plots in the tutorial Birthday Paradox.

Typing

Python started out as a dynamically typed language. However, in Python3, type annotations were introduced. We annotate the functions with types in order to clearly express the meaning of the function arguments and return values. In addition, we use the Python mypy static type checker to ensure that there are no typing errors, well before we actually execute the program. This allows us to discover a whole class of errors well before we actually run (and deploy) the code. See the type annotations in the function factorial() below, in the section on unit testing.

Unit Testing (via Pytest)

One way to check a program is to print the output to the console. That is a good start, but it is even better to do unit testing. In addition, for a program to be testable, we need to decouple the model (i.e. the data structures that describe the business logic of menus and their prices) from the view (i.e. how they are viewed, in our case on the console). This would allow us to re-use the model to view orders on other platforms such as on the web or in a mobile app (where there is no console)

In simple mode (or any other mode) you can write a function such as factorial() and test it (via Pytest) as follows:

# define function `factorial`
def factorial(n: int) -> int:
    fact = 1
    for i in range(1, n + 1):
        fact = fact * i
    return fact

# test function `factorial`
def test_factorial():
    assert factorial(0) == 1
    assert factorial(3) == 6
    assert factorial(23) == 25852016738884976640000

Pytest is built in to PythonCode and is used in the auto-grading facility. If you so wish, you can also install Pytest on your Laptop, and at the command line: pytest factorial.py