Small projectElementary20 XPExercise 5/8

A row of squares

Task

Draw a row of at least 8 squares from left to right that get gradually bigger and change colour - each square has a different colour (different shades of one colour are fine too, for example from light to dark blue). The squares do not overlap; they stand side by side. If you like, make them appear one by one.

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
    
    okno.wait(10000)
    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]
    stvorce.sort(key=lambda s: min(s.coords[0], s.coords[2]))
    okno.check("aspon 8 stvorcov", len(stvorce) >= 8, f"stvorcov: {len(stvorce)}")
    strany = [round(abs(s.coords[2] - s.coords[0])) for s in stvorce]
    okno.check("zvacsuju sa zlava doprava", all(a < b for a, b in zip(strany, strany[1:])), f"strany: {strany}")
    okno.check("kazdy ma inu farbu", len({s.fill for s in stvorce}) == len(stvorce) and all(s.fill for s in stvorce))
    okno.check("stoja vedla seba", all(min(b.coords[0], b.coords[2]) >= max(a.coords[0], a.coords[2]) - 1
                                      for a, b in zip(stvorce, stvorce[1:])))

    Expected output

    aspon 8 stvorcov: OK
    zvacsuju sa zlava doprava: OK
    kazdy ma inu farbu: OK
    stoja vedla seba: 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.