Fam4k

๐Ÿ”ฐ Project Overview

The current image has no alternative text. The file name is: family.jpg

A calculator is one of the simplest yet most effective projects to start with in Python.
You will learn:

  • Taking user input.
  • Using functions for organization.
  • Handling basic operations (addition, subtraction, multiplication, division).
  • Using conditionals to control the logic.

โœ๏ธ Step 1: Plan the Calculator

We need:

  1. A menu for users to choose an operation.
  2. Functions for each operation.
  3. A loop to keep the calculator running until the user decides to quit.

๐Ÿ–ฅ๏ธ Step 2: Write the Code

# Basic Calculator in Python

# Define operations
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):
    if b != 0:
        return a / b
    else:
        return "Error! Division by zero."

# Main program loop
while True:
    print("\n๐Ÿ“Œ Simple Calculator")
    print("1. Addition (+)")
    print("2. Subtraction (-)")
    print("3. Multiplication (*)")
    print("4. Division (/)")
    print("5. Exit")

    choice = input("๐Ÿ‘‰ Choose an operation (1-5): ")

    if choice == "5":
        print("โœ… Exiting the calculator. Goodbye!")
        break

    if choice in ["1", "2", "3", "4"]:
        num1 = float(input("Enter first number: "))
        num2 = float(input("Enter second number: "))

        if choice == "1":
            print("Result:", add(num1, num2))
        elif choice == "2":
            print("Result:", subtract(num1, num2))
        elif choice == "3":
            print("Result:", multiply(num1, num2))
        elif choice == "4":
            print("Result:", divide(num1, num2))
    else:
        print("โš ๏ธ Invalid choice, please try again.")

๐ŸŽฏ Sample Output

๐Ÿ“Œ Simple Calculator
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Exit
๐Ÿ‘‰ Choose an operation (1-5): 1
Enter first number: 10
Enter second number: 5
Result: 15.0

๐Ÿ“Š Operation Summary Table
OperationFunction UsedExample InputExample Output
Additionadd(a, b)10 + 515.0
Subtractionsubtract(a,b)10 – 55.0
Multiplicationmultiply(a,b)10 * 550.0
Divisiondivide(a,b)10 / 52.0
Division by 0divide(a,b)10 / 0Error message

๐Ÿง  Exercise for You
  • Add a power function (exponentiation).
  • Add a modulus function (remainder).
  • Improve the calculator by allowing the user to enter the operation as a symbol (+, -, *, /) instead of numbers.

๐Ÿ“ Summary

  • You learned how to build a basic calculator using Python.
  • You practiced functions, loops, conditionals, and input handling.
  • This project is the foundation for building more advanced tools like a scientific calculator.
โฌ‡๏ธ Download Fam4k ุชุญู…ูŠู„

Related Posts

Rapid_tv

๐Ÿ”น Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. ๐Ÿ‘‰ Rules: ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned…

Read more

VOD-ZalHD

๐Ÿ”น Introduction The Number Guessing Game is a classic beginner Python project. ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned ๐Ÿ”น Summary โฌ‡๏ธ Download VOD-ZalHD ุชุญู…ูŠู„ Server 1 โฌ‡๏ธ…

Read more

Delux_pro

๐Ÿ”น Introduction The To-Do List App is one of the most popular beginner projects. It teaches you how to: ๐Ÿ”น Code Example ๐Ÿ”น Features of This App ๐Ÿ”น Example Run…

Read more

Speed_HD+

1. Introduction Data visualization helps us understand patterns and insights in data by converting raw numbers into charts and graphs.In Python, the most popular libraries are: 2. Installing Required Libraries…

Read more

Dauo

1. Introduction Web scraping is the process of extracting data from websites. In Python, we commonly use libraries like requests (to fetch web pages) and BeautifulSoup (to parse and extract…

Read more

Macia_Pro

1. What is an API? 2. The requests Library The most common library for working with APIs in Python. Install if needed: 3. Making a GET Request โœ… GET requests…

Read more