I have an python example code as:
Input: (x,y)
if x==0 and y==0:
print x+y+1
elif x==0 and y==y:
print x+y*y+2
elif x==x and y==0:
print x*x+y+3
else:
print x*x+y*y+4
How can I switch directly to the condition as, if my input is (x,y) = (0,0) it will output 1 without checking other conditions?
I tried this using dictionary as,
Input: (x,y)
def Case1():
print x+y+1
def Case2():
print x+y*y+2
def Case3():
print x*x+y+3
def Case4():
print x*x+y*y+4
dict = {(0,0): Case1,
(0,y): Case2,
(x,0): Case3,
(x,y): Case4,
}
dict[(x,y)]()
When I tried this with input (x,y) = (0,0), this gives me output as 4 instead of 1. It seems like, my code is checking only for the Case4. What I am doing wrong in the dictionary?
Thanks!