Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Preparing Yourself for the Tests

It is recommended that you prepare yourself for the tests. The following should help you asses whether you need to study and practice more. It is not a sufficient preparation for the test.

Topics covered

Before the midterm

  1. primitive data types (int, float, bool, str, NoneType), operators and their order, data type conversion
  2. loops - the for loop (iterating n times, sequence traversal), the while loop (infinite loop), flow control
  3. conditionals (if, elif, else)
  4. function definition (fruitfulness, pure functions, side-effects), variable scope (namespaces), memory allocation (stack vs. heap)
  5. exceptions (raising them, understanding tracebacks)
  6. sequence data types - str, list, tuple (indexing, slicing, sequence operators)
  7. dictionary and set data types - dict, set (traversals)
  8. data type mutability (aliasing, shallow vs. deep copy), hashability, iterators

Additionally before the end-of-term

  1. modules, packages, namespaces (code organization, scripts vs. libraries, import statement)
  2. file reading and writing (with statement)
  3. paths (current working directory, relative vs. absolute paths, os.path), directories (root, current and parent directory)
  4. testing (doctest, unittest)
  5. exceptions - handling (try and except statements, specifying exception types), instantiating vs. raising exception objects
  6. instances - class definition, instance variables, method definition (__init__, __str__)
  7. objects - state, mutability, equality and copy
  8. class variables and methods, static methods, decorators (@property)
  9. naming conventions, polymorphism (inheritance, operator overloading, duck typing)

Elementary micro-tasks

The following is a set of elementary tasks in Python. It is necessary to practice these tasks to get fast and comfortable programming them. It is the prerequisite of the midterm, end-of-term and exam test. It is recommended to repeat each task until you can consistently program each under 1 minute without making any mistake:

  1. Build a list with powers of two of size 40 (i.e. [2**0, 2**1, 2**2, ..])
  2. Build a list of numbers that are divisible by 2 and 3 simultaneously and are less than 100 (i.e. [6, 12, 18, ..])
  3. Build a dictionary where the key is an integer between 1 and 10 and the value is its square root (i.e. 1 -> 1, 2-> 1.41, ..)
  4. Build a string with consecutive integers up to 100, separated by a space (i.e. “1 2 3 4 5 ..”)
  5. Write a function that returns a sum of its two parameters
  6. Divide 224 by 2 repeatedly, until it cannot be divided without a reminder

Additionally before the end-of-term

  1. Create a doctest for any function
  2. Open a non-existing file and handle the exception by printing “path doesn't exist”
  3. Create a class where the initializer assigns all its parameters to instance variables
  4. Create your own exception subtype (inherit from existing type) and raise it

Basic tasks

These tasks already pose some challenge, so it is expected that you spend a bit more time on them, by testing and debugging your solution. You are expected to complete the task within 3-5 minutes on your first try, if you want to pass the tests.

  1. Write a function that will return a list of alternating True and False values of specified size, which is a parameter of the function (i.e. [True, False, True, False, ..])
  2. Replace each non-space character in a string with 'a' (“Hello world” → “aaaaa aaaaa”)

Additionally before the end-of-term

  1. Create a module with one constant, print the constant from a script in a different file
  2. Read all lines from a file, one-by-one
  3. Add support for deep comparison for a class

Test-level tasks

For test-level tasks, see the assignments from the last years – midterm_2020.py , midterm_2021.py , endofterm_2020.py , and endofterm_2021.py . You should be able to complete each task in 8-10 minutes.

Exam-level tasks

You are expected create readable (naming conventions), documented (docstrings), and tested (unittest) code. You should be able to complete each task in about 20 minutes, including documentation and unittest writing.

It may be helpful to get additional feedback about your code quality from VS Code directly. You can enable that by unchecking “Python Linting: Pylint Use Minimal Checkers” in File → Preferences → Settings.

  1. Implement a function that converts CamelCase identifiers to snake_case
  2. Create two packages. The first one will contain two modules: library and main. Module library will contain one simple function definition that will be called in module main. The second package will contain corresponding unittest modules (test_library and test_main).
  3. Write a class Book which have attributes author and name. Further implement two functions: save_book which will save class attributes to a text file (you can choose the data format), and load_book which will return initialized Book instance.
  4. Create a class Password which will contain one string. Create a @property password_strength, which will return the password strength - one of the values “strong”, “ok”, and “weak” (you can pick any reasonable criteria). Enable password concatenation with the plus operator. When converting the instance to string, the result should be "Password(****)" for an instance containing a 4-letter password (each character is converted to an asterisk).
  5. Create a class NumericPassword which will inherit from Password. Ensure that the stored string contains numeric characters only. Make sure that all the functionality of Password works for NumericPassowrd as well. Hint: Use super() to access Password methods, e.g. in __init__.

Complex assignment for the revision lecture

  1. Create a folder for this assignment which will contain a single package for the modules described below. Choose all names appropriately. At the end, every function and method should have a unittest. Place the unittest modules in the top-level folder, not in the package. Every module, class, function and method should have a docstring.
  2. E-mail module
    1. Create a module for working with emails.
    2. Create a class that will hold a single e-mail. Its initializer should take a single argument.
    3. If the class is initialized with an invalid e-mail, a custom exception (inherited from appropriate buil-in exception) is raised.
    4. When this class is converted to a string, in the local part of the address (everything before the “@” character), the first three characters should be kept while the remeaining characters should be replaced with asterisks for privacy purposes. Example: "jenicto2@fel.cvut.cz" → "jen*****@fel.cvut.cz".
    5. Implement a method that will return the top-level domain (e.g. “cz” or “com”) and make it a property of the class.
    6. Enable equality test with both another e-mail instance and string
    7. Implement a static method that gives a suggestion when an e-mail is taken. It takes an e-mail instance as an argument and returns another e-mail instance containing a modified e-mail (e.g. add “2” after the username, so that “jenicto@fel.cvut.cz” becomes “jenicto2@fel.cvut.cz”)
    8. Create a second class for GMail whose initializer will take only the username (without the “@gmail.com”). Create a class variable to store the domain (i.e. “gmail.com”).
  3. E-mail list module
    1. Create another module that will work with e-mail lists.
    2. Create a function that will store a list of e-mails into a folder, one e-mail per file. The function takes two arguments – a list of e-mail instances and a folder path.
    3. Create a function that will load a list of e-mails from a folder. The only argument of this function is a folder path. If the folder does not exist, it returns an empty list.
  4. Example module
    1. Create a module (script) named “example”.
    2. This module will execute a simple demo that will demonstrate how to use the package.
courses/be5b33prg/test_preparation.txt · Last modified: 2022/01/06 19:16 by jenicto2