| Deutsch English |
![]()
WORKSHEET 1: PYTHON CITY |
|
The worksheet depicts a realistic scenario in the IT industry: You are employed as a programmer in a company and are supposed to continue a project of your predecessor. You are given a complex, executable programme as a template. Your task is to understand the programme and make certain adjustments. The programme draws a picture of a city. As the programme code contains random elements, the city will look different every time you run the programme.
|
WORKSHEET 2: MONDRIAN |
The programme randomly divides the GPanel window vertically and horizontally into coloured rectangles. The colours are randomly selected from the colours list. The graphics are reminiscent of the artwork of painter Piet Mondrian.
Program: # Mondrian.py from gpanel import * from random import * def between(a, b): return a + (0.2 + 0.3 * random()) * (b - a) def randomColor(): while True: result = choice(colors) return result def rect(xMin, yMin, xMax, yMax): for aColor in ('black', randomColor()): setColor(aColor) fillRectangle(xMin, yMin, xMax, yMax) xMin += delta yMin += delta xMax -= delta yMax -= delta def maybe(bias = None): return choice([False,True,bias,bias] if bias!=None else [False,True]) def draw(xMin = 0, yMin = 0, xMax = 500, yMax = 500): if xMax - xMin > threshold and yMax - yMin > threshold: if maybe(xMax - xMin > yMax - yMin): xMid = between(xMin, xMax) if maybe(): draw(xMin, yMin, xMid, yMax) rect(xMid, yMin, xMax, yMax) else: rect(xMin, yMin, xMid, yMax) draw(xMid, yMin, xMax, yMax) else: yMid = between(yMin, yMax) if maybe(): draw(xMin, yMin, xMax, yMid) rect(xMin, yMid, xMax, yMax) else: rect(xMin, yMin, xMax, yMid) draw(xMin, yMid, xMax, yMax) else: rect(xMin, yMin, xMax, yMax) makeGPanel(0, 500, 0, 500) colors = ['gray', 'lime', 'red', 'white', 'blue', 'yellow'] delta = 6 threshold = 100 setColor ('black') draw()
|
![]()