This is a small program that works as a arithmetic calculator. I have read previous questions here, but there is still a doubt. In my code, I have used 'is' and not == in my while loop, but my loop does not stop. That is kind of unexpected because the variable ask is getting assigned by a new object if the user presses 'n' when asked for input. I'd be grateful if someone can have a look on the code and help.
def Add(x,y):
add = x+y
print("Answer:",add)
def Sub(x,y):
sub = x-y
print("Answer:",sub)
def Mult(x,y):
product = float(x*y)
print("Answer:",product)
def Div(x,y):
if y!=0:
div=float(x/y)
print("Answer:",div)
else:
print("Invalid input!")
ask='y'
while(ask is 'y' or 'Y'):
x=float(input("\nEnter x:"))
y=float(input("Enter y:"))
print("\nCALCULATOR:")
print("\nPlease select any of the following options:")
print("1.Add")
print("2.Subtract")
print("3.Multiplication")
print("4.Division")
opt=int(input("\nYour option:"))
if(opt is 1):
Add(x,y)
elif(opt is 2):
Sub(x,y)
elif(opt is 3):
Mult(x,y)
elif(opt is 4):
Div(x,y)
else:
print("Invalid option!")
ask=input("\nDo you want to continue?(y/n or Y/N)")