Hide menu

732A74 Introduction to Python


This page contains the instructions for the lab assignments, as well as general information about how to work on and how to submit labs. For more information about the examination of the lab component, see the Examination page.


General information (including how to hand in)

Instructions: Submit your labs according to the instructions below. Before you submit your first lab, you and your lab partner need to sign up in Webreg.

Signing up To sign up in webreg, follow the link above (current pointing to 2020 instance) and find a free slot (or the slot with your lab partner). Sign up by clicking the link (indicated below) and entering your LiU-id:

If there are no free slots available anywhere (ie if there are too many single-person signups), write in your entire group in the looking for a lab partner group, and let me know.

Format of the subject line: 732A74-2019 lab code(your LiU-ID, your partner's LiU-ID)

Example: 732A74-2019 LA1 marjo123-andma007

If you and your lab partner are to hand in, send the message to the lab assistant and your lab partner.. Attach your lab file/files. If you're in Matteus' group, hand in to Matteus etcetera. You can see in Webreg which lab assistant you signed up for.

If only one lab partner did the work, or the overwhelming majority of the work, only that lab partner should hand in, and shouldn't send their solution to the other partner. In that case, contact your lab assistant. We adhere to the IDA lab rules.

Feedback: For each lab there are a number of scheduled hours where you can get oral feedback on your work from the lab assistants. If you submit in time for the first due date, you will get also get written feedback.

Information about notebooks

This course uses Jupyter notebooks for the lab assignments. Notebooks let you write and execute Python code in a web browser, and they make it very easy to mix code and text.

Lab environment. To work on a notebook, you need to be logged into one of IDA’s computers, either on-site or via ThinLinc. At the start of each lab session, you have to activate the course’s lab environment by writing the following at the terminal prompt:

source /courses/732A74/labenv/bin/activate
(note the updated path!)

Download and open the notebook. To start a new notebook, say L1.ipynb, download the notebook file to your computer and issue the following command at the terminal prompt.

jupyter-notebook L1.ipynb

This will show the notebook in your web browser.

Rename the notebook. One of the first things that you should do with a notebook is to rename it, such that we can link the file to your LiU-ID. Click on the notebook name (next to the Jupyter logo at the top of the browser page) and add you and your lab partners' LiU-ID:s, like so:

L1-abcde123-fghij456

How to work with a notebook. Each notebook consists of a number of so-called cells, which may contain code or text. During the lab you write your own code or text into the cells according to the instructions. When you ‘run’ a code cell (by pressing Shift+Enter), you execute the code in that cell. The output of the code will be shown immediately below the cell.

Check the notebook and submit it. When you are done with a notebook, you should click on Kernel > Restart & Run All to run the code in the notebook and verify that everything works as expected and there are no errors. After this check you can save the notebook and submit it according to the instructions below.

Lab 1: Python Basics

This lab and the introductory lecture session help you to get started with Python. The focus is on basic language features: You will be working with basic data structures such as strings, dictionaries, and lists, write loops and comprehensions to iterate over sequential data such as lists of strings.

Lab 2-3: Functions and procedural abstraction

This lab and the second lecture session help you with working with Python functions, procedural abstraction, some debugging or testing, and functional patterns. The focus is on using the basic language feature of functions, and the subdivision of problems. You will be working with functions, exceptions, assertions and various Pythonic functional constructs. You will also try out basic recursive patterns, and try out numpy.

Lab 4-5: OOP and scripts

In these final two labs, you will practice writing a simple command line Python script where you read, analyse and write text files, rule out poor choices of data structures, and structure your program. Finally, you will learn about basic OOP in Python, try out simple numpy array operations and build a crude image/vector classifier.

  • Lab 4: Scripting and text generation (note! Not a Notebook, not handed in as a notebook) (due 2020-03-04, hand in ASAP).
    shakespeare.txt (The Complete Works of Shakespeare, per Project Gutenberg)
  • Lab 5: OOP introduction, basic numpy (due 2020-03-17, hand in ASAP). The last scheduled lab is on 11/3.
    HANDIN INSTRUCTION (Urkund): It has been strongly suggested that we use the anti-plagiarism service Urkund. Urkund rejects Notebooks and .py files (even if they are simple text). So: just before you hand in lab 5, generate a PDF export of the exact notebook you're handing in (in the notebook, select File > Download as > PDF via Latex (.pdf). Then send both your notebook (.ipynb) and the PDF in the same email to your assistant. Add an open copy (CC) to anders.marak.leffler.liu@analys.urkund.se. If you are handing in to Anders, you should send both to his @liu.se address and this Urkund address. You will receive an error message from Urkund, telling you that they don't handle Notebooks. That is fine. (The reason for handing in both files in the same email is to make it easier to check that the PDF corresponds to the Notebook.). This applies to lab 5 (not 1-3). Lab 4 is not in notebook format. We may check your lab 4 handins in a similar automated fashion, but you don't need to change how you hand in.

All labs must be passed by March 31 (slightly extended due to issues with lab systems). The assistants should have the lab at least 5 work days before this to guarantee grading.

IDA general lab rules

Rules for examination of computer lab assignments at IDA

You are expected to do lab assignments in group or individually, as instructed for a course. However, examination is always based on individual performance.

It is not allowed to hand in solutions copied from other students, or from elsewhere, even if you make changes to the solutions. If there is suspicion of such, or any other form of cheating, teachers are obliged to report it to the University Disciplinary Board.

Be prepared to answer questions about details in specific code and its connection to theory. You may also be asked to explain why you have chosen a specific solution. This applies to all group members.

If you foresee problems meeting a deadline, contact your teacher. You can then get some help and maybe the deadline can be set to a later date. It is always better to discuss problems, instead of, e.g., to cheat.

Any kind of academic dishonesty, such as cheating, e.g. plagiarism or use of unauthorized assistance, and failure to comply with university examination rules, may result in the filing of a complaint to the University Disciplinary Board. The potential penalties include suspension, warning.

Policy for handing in computer lab assignments at IDA

For all IDA courses having computer lab assignments there will be one deadline during or at the end of the course. If you fail to make the deadline, you must retake the, possibly new, lab course the next time the course is given.

If a course deviates from this policy, information will be given on the course web pages.


Page responsible: Anders Märak Leffler
Last updated: 2020-03-06