Let’s look at a classic “Seven Dots Puzzle”, also known as the “Three Lines Puzzle with Seven Dots” and if we code it in Python and show the solution interactively. In this puzzle, we have seven dots arranged in a specific configuration, and the challenge is to draw three straight lines such that each dot ends up in its own separate segment.

In this post, I’ll share the runnable Python script below that draws the dots, and you can try to find the solution on your own. If you can’t, you can click on ‘Show solution’ button to see the solution on the screen. The solution will remain on for five seconds and disappear, after which, you can click the button again to show it again.
Click on run icon on the widget below to start. If you can’t find the solution on your own, click ‘Show solution’.
This puzzle is a good way to stretch your mind and practice thinking creatively and spatially.
The Method
The script uses tkinter library for the graphics and timer. The dots are pre-determined coordinates. The lines are also drawn at specific locations to ensure the solution is correct. There is no Artifical Intelligence algorithm in this code, but straight-up procedural Python code.
For more brain teasers and puzzles, click here.
I hope you found this post helpful and interesting. Explore this site for more tips and articles. Be sure to also check out my Patreon site where you can find free downloads and optional fee-based code and documentation. Thanks for visiting!