Oct-08-2019, 12:01 AM
In the following code (which is executable as-is), I've created a dictionary called switcherx{} in the switcher() function. This function also calls other functions based on the selection from switcherx{}. This is the only place these functions are called from, and the only place I call switcher() is in the while loop at the bottom of the code. Nevertheless, even when I comment out the function call inside of switcher(), the functions still get called. Why is this? Furthermore, if I select "Stop" (1) from the code's menu, the tankSelect() function still gets called, even though the stop() function doesn't call it. I don't know if that's related to the first problem or not. Thanks for any tips.
def tankSelect(): b = """ 1 = Tanks topped off 2 = Tanks to tabs 3 = Enter tank amounts """ while(True): print(b) try: c = int(input("Selection: ")) if ((c < 1) | (c > 3)): print("Invalid input1.") continue break except: print("Invalid input2.") continue if (c == 1): leftFuel = 40.5 rightFuel = leftFuel elif (c == 2): leftFuel = 23.5 rightFuel = leftFuel return c def stop(): return def left(): tankSelect() return def right(): tankSelect() return def switch(): tankSelect() return def switcher(arg): switcherx = { 1: stop(), 2: left(), 3: right(), 4: switch() } # func = switcherx.get(arg, "Invalid input7.") # print(func) print("here3") return a = """ 1 to stop 2 to start on left tank 3 to start on right tank 4 to switch tanks """ while (True): print(a) try: y = int(input("Selection: ")) switcher(y) except: print("Invalid input8.")