Simple Calculator with Pyhton

🧮 Program Purpose

This Python program is a simple calculator that allows the user to:

✅ Choose an operation
✅ Enter two numbers
✅ See the calculated result

Supported operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division
Step-by-Step Explanation:
1. Display the Menu
2. Get User Choice
3. Get Numbers from User
4. Perform Operation Based on Choice
Python checks the condition using if-elif-else.
  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Division by Zero Protection
5. Handle Invalid Input

Python Code :

print("Select operation:")

print("1. Addition")

print("2. Subtraction")

print("3. Multiplication")

print("4. Division")

choice = input("Enter your choice (1/2/3/4): ")

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

if choice == '1':

    print("Result =", num1 + num2)

elif choice == '2':

    print("Result =", num1 - num2)

elif choice == '3':

    print("Result =", num1 * num2)

elif choice == '4':

    if num2 != 0:

        print("Result =", num1 / num2)

    else:

        print("Error: Cannot divide by zero!")

else:

    print("Invalid choice")


 Example Run

Select operation:
1. Addition
2. Subtraction
3. Multiplication
4. Division

Enter your choice (1/2/3/4): 4
Enter first number: 10
Enter second number: 2
Result = 5.0
    

Key Concepts Used

print() → display text
input() → read user input
float() → convert to decimal number
if / elif / else → decision making
✔ nested if → check division safety


 Why This Program is Good for Beginners

✅ teaches user input
✅ introduces conditions
✅ shows error handling
✅ demonstrates arithmetic operations





Comments

Popular posts from this blog

materi Asking and Giving Attention (Meminta dan Memberi Perhatian) dalam bahasa Rusia

20 Fundamental Spring Boot yang wajib diketahui Pemula Programmer spesialis Java Developer

Daftar Kata Kunci (Keyword) dalam Bahasa Pemrograman Python

Tujuh daftar situs terpercaya untuk melamar kerja ke Austria bagi pelamar dari luar negeri:

percakapan KERETA JARAK JAUH dalam bahasa Rusia

Regression Testing dalam UAT Environment?

Python Date and Time Manipulation

TOP 8 Framework Populer menggunakan bahasa .NET

CRUD SPRING REACTIVE WEBFLUX +Mongo DB

Program Python yang menyelesaikan sistem persamaan linear menggunakan metode eliminasi Gauss