Skip to content
Home » Simple Calculator in Python

Simple Calculator in Python

Learn about Simple Calculator in Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Simple Calculator in Python

# Python program to make a simple calculator

# input from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

# choise selection
print("Operation: +, -, *, /")
select = input("Select operations: ")

# check operations and display result
# addition of two numbers
if select == "+":
    print(num1, "+", num2, "=", num1+num2)

# subtraction two numbers
elif select == "-":
    print(num1, "-", num2, "=", num1-num2)

# multiplication two numbers
elif select == "*":
    print(num1, "*", num2, "=", num1*num2)

# dividesion two numbers
elif select == "/":
    print(num1, "/", num2, "=", num1/num2)

else:
    print("Invalid input")

Output:

Enter first number: 3
Enter second number: 5
Operation: +, -, *, /
Select operations: -
3.0 - 5.0 = -2.0

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Absolute Value in Python for Complex Number