Write a programBasic10 XPExercise 6/8

A little house

Task

Draw a little house: a square body (create_rectangle) and above it a triangular roof (create_polygon or create_line). The roof's base is the top corners of the square and its tip is above the house.

The program runs in a tkinter simulation right in your browser - after Run you see the window and can click it. The tests click and check what was drawn on the canvas.

Examples

  • Call

    from tkinter import _mente as okno
    
    stvorce = [r for r in okno.items("rectangle")
               if abs(abs(r.coords[2] - r.coords[0]) - abs(r.coords[3] - r.coords[1])) < 1]
    okno.check("dom ma stvorcove telo", len(stvorce) >= 1)
    if stvorce:
        s = stvorce[0]
        lavy, pravy = sorted([s.coords[0], s.coords[2]])
        horny = min(s.coords[1], s.coords[3])
        body = [(round(x), round(y)) for i in okno.items() if i.kind in ("line", "polygon")
                for x, y in zip(i.coords[0::2], i.coords[1::2])]
        okno.check("strecha zacina v hornych rohoch", (round(lavy), round(horny)) in body and (round(pravy), round(horny)) in body)
        okno.check("strecha ma vrchol nad domom", any(lavy < x < pravy and y < horny for x, y in body))

    Expected output

    dom ma stvorcove telo: OK
    strecha zacina v hornych rohoch: OK
    strecha ma vrchol nad domom: OK

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.