In [ ]:
 
In [ ]:
# This function adds two numbers
def add(x, y):
    return x + y

# This function subtracts two numbers
def subtract(x, y):
    return x - y

# This function multiplies two numbers
def multiply(x, y):
    return x * y

# This function divides two numbers
def divide(x, y):
    return x / y

def menu():
    print("Welcome to the calculator!")
    print("You can enter an operation and two numbers to add, subtract, multiply and divide.")

    print("Select a number operation")
    print("1. Addition")
    print("2. Subtraction")
    print("3. Multiplication")
    print("4. Division")

menu()
while True:
    calculatorfile = open("my_calculator.txt", "+a")
    choice = input("make choice==>")

    if choice in ("1", "2", "3", "4"):
        try:
            numOne = float(input("numOne ==>"))
            numTwo = float(input("numTwo ==>"))
        except ValueError:
            print("enter a number")
            
        if choice == "1":
            print("{} + {} = {}".format(numOne, numTwo, add(numOne, numTwo)))
            myValue = "{} + {} = {}\n".format(numOne, numTwo, add(numOne, numTwo))
            calculatorfile.write(myValue)
            calculatorfile.close()
        elif choice == "2":
            print("{} - {} = {}".format(numOne, numTwo, subtract(numOne, numTwo)))
            myValue = "{} - {} = {}\n".format(numOne, numTwo, subtract(numOne, numTwo))
            calculatorfile.write(myValue)
            calculatorfile.close()
        elif choice == "3":
            print("{} * {} = {}".format(numOne, numTwo, multiply(numOne, numTwo)))
            myValue = "{} * {} = {}\n".format(numOne, numTwo, multiply(numOne, numTwo))
            calculatorfile.write(myValue)
            calculatorfile.close()
        elif choice == "4":
            print("{} / {} = {}".format(numOne, numTwo, divide(numOne, numTwo)))
            myValue = "{} / {} = {}\n".format(numOne, numTwo, divide(numOne, numTwo))
            calculatorfile.write(myValue)
            calculatorfile.close()

            # Check if the user wants another calculation
            # Break the code if answer is no
        next_calculation = input("Do you want to do another calculation? <Enter> for yes or N for no.")
        if next_calculation == "n" or next_calculation == "N":
            print("Thanks for using the calculator, Goodbye! :)")
            break
            finalcalculation = myValue

        menu()
                
Welcome to the calculator!
You can enter an operation and two numbers to add, subtract, multiply and divide.
Select a number operation
1. Addition
2. Subtraction
3. Multiplication
4. Division
make choice==>1

¶

In [ ]: