Simple arithmetics (5 min). Calculate:
Are they results like you expected?
Lists (30 min). Define following lists:
Introspection (20 min). In Python interpreter define following variables:
Using built-in dir and help method find out which methods these data structures offer. Print a table with non-special methods (without underscores) and first line of their docstring. 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 (45 min). Implement a simple cashier machine with the following features :
Import. Write a program that counts lines and characters in a file. With your editor, code a Python module called mymode.py which provides three functions:
Next, test your module interactively, using import. What if your module is in a different directory than your current working directory? Add a "main" function to your module.
Geometry. Create a Point class that consists of an ordered pair (x,y) representing a point's location on the X and Y axes. X and Y coordinates are passed to the constructor on instatiation and default to origin for any missing coordinate.
Ecosystem (1h). Program an ecosystem in which each organism belongs to a hierarchical tree (for example, dog is a mamal, mamal is an animal, an animal is a living organism). Implement following functions and attributes:
In each iteration each organism should update its state (move, reproduce or die). You can also provide a simple ASCII output showing the position of the organisms.
As a starting point you can take the program ecosystem.py