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

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...