The final mini project — A digital counter

Lesson 26 of 26 · Basic Python

In this final mini project we will make a digital counter — a program that remembers one number and lets that value be increased, decreased or reset.

This project is very important because it connects almost everything you have learned so far: variables, the while loop, branching and working with user input.


1. What is a counter?


A counter is a variable that remembers a value and changes while the program runs. Most often it starts from zero and then increases or decreases.

Examples of counters from everyday life:

  • The number of steps on a smartwatch
  • The number of cars that have passed through a crossroads
  • The number of points in a game
  • The number of times a button is pressed

In programming counters are used very often because they let us follow the state of a program over time.


2. Where are digital counters used?


Digital counters are used in:

  • games (points, lives, levels)
  • vending machines and devices (the number of products)
  • traffic lights (counting down time)
  • embedded systems and microcontrollers

That is why this project is ideal preparation for MicroPython, where you will connect the counter to real buttons and LEDs.


3. The task


Make a program that:

  • has one variable that is the counter
  • keeps printing the current value of the counter
  • reacts to the user's commands

The commands are:

  • + → increases the counter by 1
  • - → decreases the counter by 1
  • r → resets the counter to 0
  • q → exits the program

4. How do we think about the solution?


For the program to keep running and waiting for commands, we need an infinite while loop.

We keep the counter in one variable, and we check the user's input with if / elif / else branching.


5. Programming the digital counter



counter = 0  # the starting value of the counter

while True:
    print("Current value:", counter)
    command = input("+, -, r or q: ")

    if command == "+":
        counter += 1
    elif command == "-":
        counter -= 1
    elif command == "r":
        counter = 0
    elif command == "q":
        break

6. Explaining the code


  • counter = 0 — sets the starting value of the counter
  • while True — the program keeps running until we stop it
  • input() — takes a command from the user
  • counter += 1 — increases the counter
  • counter -= 1 — decreases the counter
  • break — leaves the loop and ends the program

7. Preparing for MicroPython


In MicroPython, instead of the keyboard you will use:

  • buttons for increasing and decreasing the counter
  • LEDs or a display for showing the value

The most important thing is that the logic of the program does not change. Only the way data is entered and shown changes.


If you understand this project — you are ready to move from Python to MicroPython and work with real devices.