In [53]:
#!/user/bin/env python3

#This Function Adds Two Number
def myAdd(x,y):
    return x + y

#This Function Subtracts Two Number
def mySub(x,y):
    return x - y

#This Function Multiplies Two Number
def myMulti(x,y):
    return x * y

#This Function Divides Two Numbers
def myDivi(x,y):
    return x / y

while True:
    print("Type 1 to Add, Type 2 to Subract, Type 3 to Multipy, Type 4 Divide")
    choice = input("==>")

    if choice in ("1", "2", "3", "4"):
        try:
            numOne = int(input("numOne==>"))
            numTwo = int(input("numTwo==>"))
        except ValueError:
            print("Enter a number")
            continue

        if choice =="1":
            print("{} + {} = {}".format(numOne, numTwo, myAdd(numOne, numTwo)))
            output = myAdd(numOne, numTwo)
            rule = "+"
        if choice =="2":
            print("{} - {} = {}".format(numOne, numTwo, mySub(numOne, numTwo)))
            output = mySub(numOne, numTwo)
            rule = "-"
        if choice =="3":
            print("{} * {} = {}".format(numOne, numTwo, myMulti(numOne, numTwo)))
            output = myMulti(numOne, numTwo)
            rule = "*"
        if choice =="4":
            print("{} / {} = {}".format(numOne, numTwo, myDivi(numOne, numTwo)))
            output = myDivi(numOne, numTwo)
            rule = "/"

        #Opening Calculator Text File 
        with open("Calculator.txt", "+a") as f:
            #Formatting Output to the Calculator Text File
            f.write(f"{numOne} {rule} {numTwo} = {output}\n")

    goAgain = input("Go Again <enter> again or No ==>")
    if goAgain == "No" or goAgain == "no":
        print("Goodbye, Have a Good Day!!")
        break
        
Type 1 to Add, Type 2 to Subract, Type 3 to Multipy, Type 4 Divide
==>3
numOne==>6
numTwo==>8
6 * 8 = 48
Go Again <enter> again or No ==>enter
Type 1 to Add, Type 2 to Subract, Type 3 to Multipy, Type 4 Divide
==>4
numOne==>9
numTwo==>3
9 / 3 = 3.0
Go Again <enter> again or No ==>No
Goodbye, Have a Good Day!!

¶

In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: