0

Python Calculator

A simple Python-based calculator that supports basic arithmetic operations with an interactive user interface.

The Python Calculator is a straightforward yet interactive command-line application that allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It is designed to be user-friendly and provides a seamless experience for quick calculations.

Overview

This project demonstrates how to implement a simple calculator in Python. It uses a menu-driven approach where users can select the desired operation, input two numbers, and receive the result. The program also supports continuous calculations, allowing users to perform multiple operations without restarting the application.

Features

  • Interactive Menu: Users can select operations through a numbered menu.
  • Basic Arithmetic Operations:
    • Addition
    • Subtraction
    • Multiplication
    • Division
  • Input Validation: Ensures that user inputs are valid numbers and handles division by zero gracefully.
  • Continuous Calculations: After completing an operation, users can choose to perform another calculation or exit the program.
  • User-Friendly Design: Clear prompts and error messages make the application easy to use.

Technical Details

  • Code Structure:
    • Operation Selection: The program uses a menu-driven approach to let users select the desired operation.
    • Input Handling: Prompts the user for two floating-point numbers and validates the input.
    • Arithmetic Functions: Separate functions for addition, subtraction, multiplication, and division.
    • Loop for Continuity: A loop allows users to perform multiple calculations without restarting the program.
    • Error Handling: Includes checks for invalid inputs and division by zero.

How to Run

To run the calculator, follow these steps:

  1. Clone the repository:

    $ git clone https://github.com/Teto03/calculator.py
  2. Navigate to the project directory:

    $ cd calculator.py
  3. Run the Python script:

    $ python calculator.py

Example Usage

  1. The program displays a menu:

    Select operation:
    1. Add
    2. Subtract
    3. Multiply
    4. Divide
  2. The user selects an operation by entering the corresponding number (e.g., 1 for addition).

  3. The program prompts the user to input two numbers:

    Enter first number: 5
    Enter second number: 3
  4. The result is displayed:

    The result is: 8.0
  5. The user is asked if they want to perform another calculation:

    Do you want to perform another calculation? (yes/no)

Notes

  • This project is intended as a learning tool for beginners in Python programming.
  • It demonstrates the use of functions, loops, and basic input validation.
  • The program is lightweight and runs on any system with Python installed.

For more details, refer to the GitHub repository.

Credits

This project was developed as part of a personal learning initiative to explore Python programming concepts. It showcases the implementation of a simple yet functional calculator.

Contributors:

  • Stefano Brighenti
  • Daniele Buser
  • Hicham Benbouzid