Simple Calculator in Python

  This program is a simple calculator that performs addition, subtraction, multiplication, and division.

 
op = input("Enter operator (+, -, *, /): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
 
if op == '+':
    print(num1 + num2)
elif op == '-':
    print(num1 - num2)
elif op == '*':
    print(num1 * num2)
elif op == '/':
    if num2 != 0:
        print(num1 / num2)
    else:
        print("Error! Division by zero.")
else:
    print("Invalid operator")

No comments:

Post a Comment

Lists in Python

Introduction: In the realm of Python, lists stand as one of the most versatile and widely used data structures. A list is an ordered, muta...

Post Count

Loading...