Python Calculator

Here's a Python program that performs basic arithmetic operations (addition, subtraction, multiplication, division) based on user input:

Python code : 

def add(x, y):

    return x + y

def subtract(x, y):

    return x - y

def multiply(x, y):

    return x * y

def divide(x, y):

    if y == 0:

        return "Error: Division by zero!"

    return x / y

print("Select operation:")

print("1. Addition")

print("2. Subtraction")

print("3. Multiplication")

print("4. Division")

while True:

    choice = input("Enter choice (1/2/3/4): ")

    if choice in ('1', '2', '3', '4'):

        num1 = float(input("Enter first number: "))

        num2 = float(input("Enter second number: "))

        if choice == '1':

            print("Result:", add(num1, num2))

        elif choice == '2':

            print("Result:", subtract(num1, num2))

        elif choice == '3':

            print("Result:", multiply(num1, num2))

        elif choice == '4':

            print("Result:", divide(num1, num2))

    else:

        print("Invalid input!")

    again = input("Do you want to perform another calculation? (yes/no): ")

    if again.lower() != 'yes':

        break

Output
Select operation:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter choice (1/2/3/4): 1
Enter first number: 20
Enter second number: 20
Result: 40.0
Do you want to perform another calculation? (yes/no): yes
Enter choice (1/2/3/4): 2
Enter first number: 10
Enter second number: 20
Result: -10.0
Do you want to perform another calculation? (yes/no): yes
Enter choice (1/2/3/4): 3
Enter first number: 10
Enter second number: 20
Result: 200.0
Do you want to perform another calculation? (yes/no): yes
Enter choice (1/2/3/4): 4
Enter first number: 10
Enter second number: 20
Result: 0.5

This program defines four functions for performing addition, subtraction, multiplication and division. It then presents a menu to the user asking them to select an operation. Based on the user's choice, it prompts the user to enter two numbers and performs the selected operation. It handles division by zero error and provides an option to perform another calculation if the user wishes to continue.