August 2021
Beginner to intermediate
118 pages
1h 29m
English
| Puzzle 11 | Click the Button |
| 1: | display = [] |
| 2: | buttons = [] |
| 3: | for n in range(10): |
| 4: | # A button is a function called when user clicks on it |
| 5: | buttons.append(lambda: display.append(n)) |
| 6: | |
| 7: | btn = buttons[3] |
| 8: | btn() |
| 9: | print(display) |
Guess the Output | |
|---|---|
|
|
Try to guess what the output is before moving to the next page. |
This code will print: [9]
You probably expected [3] since each lambda appends its n to display.
However, the ...
Read now
Unlock full access