Simple arithmetics (5 min). Calculate:
- $2^5$
- 31/2
- 015 + 32
- 11 mod 2
Are they results like you expected?
Lists (30 min). Define following lists:
- Odd numbers from 1 to 11. Hint: Use range method.
- A list of arbitrary number of zeros
- Sequence of letters from "a" to "k". Hint: use chr method.
- Elements of power series ($A_i = \sum_{k=1}^{i} x^i$,
x = 1.2) smaller than a 10.
- 10x10 identity matrix.
Introspection (20 min). In Python interpreter define following variables:
- empty string
- empty list
- empty dictionary
Using built-in dir and help method find out which methods
these data structures offer.
Give a working example documenting at least one of the listed methods.
Enigma (20 min). Recover the message hidden in the string using the
following translation: a ➔ c, b ➔ d, ..., z ➔ b.
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr
amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q
ufw rfgq rcvr gq qm jmle. sqgle qrp.rpylqjyrc() gq pcamkkclbcb!
Binary conversion (20 min). Write a program converting integers to
their binary representation. You can store the result either in a list
or in a string.
Cashier (1,5 h). Implement a simple cashier machine with the
following features :
- read the price list from a file (for example, using the
csv module)
- implement an interactive entry of a codebar or a product name.
Hint: use raw_input
- make sure that the product names can be given in upper-, lower-
or mixed-case (they should be case insesitive)
- try to add an item not on the price list to the basket. What
happens? Add exception handling (try... except... clause) for
this case.
- add a function which nicely formats the bill (with fixed column
widths and column headers) and prints it to standard output
- refactor code so that each seperate task is handled by seperate
function (reading price list, checking out, printing the bill)
- write simple tests to check if the functions return a correct
output for a pre-defined inputs. Store the tests in a seperate
file called tests.py.