I'm trying to make a simple calculator in python. But somewehere in my code there is a problem and I know it's in the while loop. What I want to do is, whenever the user types anything but +,-,*,/ I want the program to automatically ask again for operation and start over this process. The code:
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
def add(n1,n2): return n1 + n2
def sub(n1,n2): return n1 - n2
def div(n1,n2): return n1 / n2
def mult(n1,n2): return n1 * n2
def exp(n1,n2): return n1 ** n2
print("Choose operation (+, -, *, /, ^): ")
operation = input()
while operation != '+' or '-' or '*' or '/' or '^':
print("Invalid operation, try again (+, -, *, /, ^): ")
break
else:
if operation == '+':
print(n1,"+",n2,"=",add(n1,n2))
elif operation == '-':
print(n1,"-",n2,"=",sub(n1,n2))
elif operation == '*':
print(n1,"*",n2,"=",mult(n1,n2))
elif operation == '/':
print(n1,"/",n2,"=",div(n1,n2))
elif operation == "^":
print(n1,"^",n2,"=",exp(n1,n2))