Mosh gave me an exercise to create a simple calculator, Ill admit this is not all my own work ( wished I could say it was) Im trying to add a while loop so that I can ask user if they would like to do another calculation.
Here is the code…..
def add(x, y):
return x + y
def subtract(x,y):
return x - y
def devide(x, y):
return x / y
def multiply(x, y):
return x \* y
num1 = float(input("Enter First Number: "))
num2 = float(input("Enter Second Number: "))
print (“select operation.”)
print (“1, Add”)
print (“2, Subtract”)
print (“3, Devide”)
print (“4, Multiply”)
choice = input(“Enter Choice (1/2/3/4):”)
if choice == “1”:
print(num1, "+" ,num2, "=", add(num1,num2))
elif choice == “2”:
print(num1, "-" ,num2, "=", subtract(num1,num2))
elif choice == “3”:
print(num1, "/" ,num2, "=", devide(num1,num2))
elif choice == “4”:
print(num1, "\*" , num2, "=", multiply(num1,num2))
else:
print("invalid option")