My First Python Program: A Simple Calculator

 Today, I am going to create a simple calculator using Python.

This might be your first code ever, and honestly, this is also my first Python code. So don’t worry — we are learning together.

Let’s start step by step.

Step 1: Open VS Code

First, open Visual Studio Code (VS Code).

Step 2: Create a Folder and a File

  1. Create a new folder (you can name it anything).
  2. Inside the folder, create a new file.
  3. In my case, I named the file first.py.

👉 .py is the file extension for Python, just like:

  • .cpp for C++
  • .java for Java

Step 3: Write the Python Code

Now, write the following code in first.py:

num1 = float(input("Enter num 1: "))  # Taking first number from the user
num2 = float(input("Enter num 2: ")) # Taking second number from the user
opr = input("Enter operator: ") # User selects the operator (+, -, *)
if opr == "+": # If operator is +
output = num1 + num2
if opr == "-": # If operator is -
output = num1 - num2
if opr == "*": # If operator is *
output = num1 * num2
print("Your calculation is:", output) # Displaying the result

Explanation (Very Simple)

  • input() takes values from the user
  • float() converts input into numbers
  • if conditions check which operator you selected
  • Python uses indentation (spaces) instead of brackets {}

Step 4: Save the File

Press Ctrl + S to save the file.

Step 5: Run the Program

  1. Open a new terminal in VS Code.
  2. Make sure the terminal is opened in the same folder where first.py exists.
  3. Run the command:
python first.py

Step 6: Use Your Calculator

  • Enter the first number
  • Enter the second number
  • Enter the operator (+, -, or *)
  • You will see the result on the screen

🎉 Your calculator is ready!

Final Words

This is my first Python program, and I’m really excited to share it with you.
If you are a beginner, trust me — everyone starts from here.

If you like this blog, please share it with others and keep learning 🚀
Happy Coding!

🌐 Online References


Comments

Popular posts from this blog

📘 Understanding Prometheus in a Simple Way-Part 3 (For DevOps Beginners)

Grafana Setup & Dashboard Creation (Part-5)— Explained by Raees Yaqoob Qazi