Define yourself a list containing several elements (different value!). Find an elegant way of deleting a specific element from the list. Tip: index(). [ Solution ]
Many programming language know the concept of stacks. Python has its own equivalent (Queue), but write your own version of a stack. It should emit exeptions, if it’s empty or full. [ Solution ]
In yesterday’s exercise 4 we determined whether a year was a leap year. Try to accomplish the same task using list comprehensions. [ Solution ]
When working with large data, e.g. larger than 10000 elements, one should consider a less memory consuming alternative: Generator Expressions. Try to solve the last exercise using generator expressions. [ Solution ]
Hamster – Write a script containing a hamster and a board object. The hamster shall move in a pattern and avoid obstacles on the board. Finally the board should have means to display the hamster’s motion. [ Solution ] [ Video ]
Polynome – Define a class for polynomials. One shall be able to define, derive, integrate and do math with polynomials. Do not use tools from the module numpy. [ Solution ]
Rational numbers – Design a class for rational numbers allowing the four arithmetics. This class shall also be able to return the reduced fraction or a float. Remember:
A fraction can be fully reduced by dividing numerator and dominator by the greatest common divisor.
Rational numbers are presentated as a fraction p/q, where p ∈ Z and q ∈ N\0.
Calculator – Write a calculator GUI using Tk. The user shall be able to choose a function name (RadioButtons?) and enter a value, which shall be passed to the function, in a separate window (TopLevel?). The shall be closed, if the value is OK, and the result shall be displayed in the initial window. [ Solution ]
Write a simple Tic-Tac-Toe game using Tk. But do not forget to save important data, e.g. which field has been hit by which player! [ Solution ]
Write a script for managing a phone book. Write a GUI for managing entries and export/import to/from a file or database. [ Solution ]
Racetrack – Write a threaded script for simulating a horse race. Horses shall be independently moved forward and the progress shall be displayed in a GUI, where also the winner shall be announced. [ Solution ]
Arrays – Getting used to
Create a 3 × 3-array with arbitrary values not equal 0 and resize it to a 9 × 6 array.
Assign a m × n-slice (m, n != 0, 1, m != n) of the array to a variable.
Set all elements of the slice equal 3/2 pi.
Define an array with length 100 for each property:
Distance between elements is logarithmic.
The array is empty.
Resize your 9 × 6 array to a 4 × 13 array and to a 1-dim. array.
We have seen select and piecewise. What is the difference between them and where?