Preplp
Daily Python
Day 3Python~35 min

Numbers & Math

Arithmetic operators and a mini calculator

Track progress0/15 days
x

What you'll learn

int()float()+-*///%**
  • Read numeric input from the user
  • Perform addition, subtraction, multiplication, and division
  • Understand floor division, modulus, and exponents
  • Build a calculator that processes two numbers

Lesson & examples

Read the code, then the explanation — try changing values before the project.

Sum two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
result = num1 + num2
print(f"The sum of {num1} and {num2} is {result}")
All operators
a, b = 5, 3
print(f"Addition: {a + b}")
print(f"Subtraction: {a - b}")
print(f"Multiplication: {a * b}")
print(f"Division: {a / b}")
print(f"Floor Division: {a // b}")
print(f"Modulus: {a % b}")
print(f"Exponentiation: {a ** b}")

Today's exercise: Simple Calculator

Read two numbers and display the results of add, subtract, multiply, and divide (handle divide-by-zero).

Steps

  1. 1

    Get two numbers

    Use float(input(...)) so decimals work too.

  2. 2

    Calculate results

    Store addition, subtraction, multiplication. For division, check if the second number is zero.

  3. 3

    Display formatted output

    Print a header and each operation on its own line with clear labels.

Full project source — copy into a folder or use the zip above

starter.py
# Simple Calculator

number1 = float(input("Enter the first number: "))
number2 = float(input("Enter the second number: "))

addition = number1 + number2
subtraction = number1 - number2
multiplication = number1 * number2
division = number1 / number2 if number2 != 0 else "Cannot divide by zero"

print("\n--- Calculator Results ---")
print(f"Addition: {number1} + {number2} = {addition}")
print(f"Subtraction: {number1} - {number2} = {subtraction}")
print(f"Multiplication: {number1} x {number2} = {multiplication}")
print(f"Division: {number1} / {number2} = {division}")

Code explained

  1. 1.Ternary for divide-by-zero

    If number2 is 0, division would crash. This one-line if/else picks either the result or a safe message.

    Snippet
    division = number1 / number2 if number2 != 0 else "Cannot divide by zero"
  2. 2.float(input())

    Using float instead of int allows decimal bills and measurements in the calculator.

Sample output

Enter the first number: 10
Enter the second number: 4

--- Calculator Results ---
Addition: 10.0 + 4.0 = 14.0
Subtraction: 10.0 - 4.0 = 6.0
Multiplication: 10.0 x 4.0 = 40.0
Division: 10.0 / 4.0 = 2.5

One rehearsal platform

Certification mocks, daily lessons, project labs, and in-browser drills

Structured for exam day and portfolio proof — timed tests, guided builds, and quick reps on one platform.