DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

Project: Develop a CLI Calculator App in Termux – Day 1 to 5

If you’ve ever thought, “I need to build something small but useful in Termux,” then this 5-day CLI calculator project is for you. By the end of this guide, you’ll have your very own command-line calculator app running on your Android device — and more importantly, you’ll have learned enough to tackle bigger projects like mini networking tools or even lightweight automation scripts.


Why a CLI Calculator?

Before you dismiss this as too basic, hear me out. A CLI calculator is the perfect starter project:

  • It builds your confidence with Python and Bash scripting.
  • You’ll learn to structure your code logically — a skill that scales.
  • It prepares you for automation tasks like log parsing or even network scans.

Plus, in the cybersecurity space, scripting even simple tools is a core skill. Whether you’re building phishing detectors, working with APIs, or integrating security tools, these fundamentals carry over.


Day 1 – Setting Up the Environment

Start with a clean Termux setup. If you’re new, check out this post on initial configurations. Run:

pkg update && pkg upgrade
pkg install python git nano

Once Python is installed, verify it:

python --version

That’s it for Day 1 — your environment is ready. You’ve laid the foundation for everything that follows.


Day 2 – Writing the Basic Script

Create a new Python file:

nano calculator.py

Paste this:

def add(a, b): return a + b
def subtract(a, b): return a - b
def multiply(a, b): return a * b
def divide(a, b): return a / b if b != 0 else "Error: Division by zero"

while True:
    print("\n1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit")
    choice = input("Choose an option: ")

    if choice == '5':
        break

    a = float(input("Enter first number: "))
    b = float(input("Enter second number: "))

    if choice == '1':
        print("Result:", add(a, b))
    elif choice == '2':
        print("Result:", subtract(a, b))
    elif choice == '3':
        print("Result:", multiply(a, b))
    elif choice == '4':
        print("Result:", divide(a, b))
    else:
        print("Invalid choice. Try again.")

Run the script with:

python calculator.py

Day 3 – Improving the User Experience

By now, the app works but feels raw. Let’s make it cleaner:

  • Add colors using colorama:
pip install colorama
  • Refactor the code into functions for better readability.
  • Add error handling for non-numeric inputs.

This is where you start thinking like a developer, not just a coder. Want to explore automation next? Look into tunneling tools to integrate APIs with your scripts.


Day 4 – Adding Features

Let’s make it more than just a calculator:

  • Implement a “history” feature by saving operations to a text file.
  • Add a percentage calculation option.
  • Include a square root or power function.
import math

def percentage(a, b):
    return (a / b) * 100

Adding features is a great way to challenge yourself and keep the momentum going. Just like when you try advanced scripts for Wi-Fi testing, complexity comes in small steps.


Day 5 – Packaging and Sharing

By now, you have a fully functional CLI calculator. Let’s package it so others can use it:

  • Create a dedicated folder for your app.
  • Add a README.md explaining how to use it.
  • Upload to GitHub for easy sharing.

If you’re serious about security, remember to follow basic security practices — even for small scripts. Many open-source tools get exploited because of poor permissions or exposed tokens.


Next Steps

Congratulations! You’ve built your first CLI app in Termux. Now, where to next? Here are some project ideas:

Your calculator project isn’t just a calculator — it’s a stepping stone. Keep building, keep experimenting, and you’ll soon find yourself confident in larger Termux projects, whether it’s security automation, API integrations, or even hosting a mini web server.


Final Thoughts

Small projects like this are the secret to mastering Termux. They build practical skills that will help you understand more complex tools, like those used in enterprise security setups or business-level risk management. And if you ever doubt the importance of practicing with “simple” scripts, remember — the pros started small too.

Top comments (0)