This is a python calculator. I developed a part here. but, In this calculator, when the user enters two wrong numbers or one wrong operator, the reset function is given by $ + enter. How to add reset capability to code?
How to use the select_op function in Conditions correctly?
How to print the menu again at the end of all activities?
while True:
print("Select operation.")
print("1.Add : + ")
print("2.Subtract : - ")
print("3.Multiply : * ")
print("4.Divide : / ")
print("5.Power : ^ ")
print("6.Remainder: % ")
print("7.Terminate: # ")
print("8.Reset : $ ")
# take input from the user
choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
print(choice)
if choice in ('1', '2', '3', '4', '5', '6', '7', '8'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
#calculate user input numbers
if(select_op(choice) == 1):
print(num1 , " + " , num2 , " = " , add(num1,num2))
elif(select_op(choice) == 2):
print(num1 , " - " , num2 , " = " , subtract(num1,num2))
elif(select_op(choice) == 3):
print(num1 , " * " , num2 , " = " , multiply(num1,num2))
elif(select_op(choice) == 4):
print(num1 , " / " , num2 , " = " , divide(num1,num2))
elif(select_op(choice) == 5):
print(num1 , " ^ " , num2 , " = " , power(num1,num2))
elif(select_op(choice) == 6):
print(num1 , " % " , num2 , " = " , remainder(num1,num2))
elif(select_op(choice) == 7):
print(num1 , " # " , num2 , " = " , terminate(num1,num2))
else:
print("Not a valid number,please enter again")
else:
print("Unrecognized operation")
#program ends here
print("Done. Terminating")
exit()