0

I am trying to only return a value if the user inputs a or b but regardless of what I input I can never get to the else statement to return the input. It continuously calls the function. Is there a better way to do this?


    def display_menu():
        print(f"Conversions Menu:\na. Feet to Meters\nb. Meters to Feet")
        usrInput=input(f"Select a converions(a/b): ").lower()
        if usrInput != "a" or "b":
            print("failed")
            print(f"please enter a or b")
            display_menu()
        else:
            return(usrInput)

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Welcome to Stack Overflow. Aside from the logical test being wrong, there is another problem with this code: simply calling `display_menu` recursively **will not** cause the value from the recursive call to be returned - it is **just like** calling **any other function**. Normally a simple `while` loop should be used instead of this kind of recursion. I added the relevant duplicate links to explain the problem in detail and to show the normal technique. – Karl Knechtel Oct 18 '22 at 18:22

0 Answers0