0

I am trying to make a prompt generator, where the user chooses between simple or complex prompts. The MAIN function is meant to repeat after the user makes their choice but the if statement I’ve written for it (reduced to its barebone) skips straight to the else result. I know if statements and the like will default to else should all other options produce false or fail, but I can’t seem to figure out why that happens here.


def Ask():
    answer = input("Do you want a simple (1) or complex (2) prompt?: ")
    return answer

def Simple():
    print("Simple has been executed")
    
def Complex():
    print("Complex has been executed")
    
def MAIN():
    user_choice = Ask()
    
    if user_choice == 1:
        Simple()
        MAIN()
    elif user_choice == 2:
        Complex()
        MAIN()
    else:
        print("Please only type 1 or 2.")
        MAIN()
    
MAIN()

1 Answers1

0

if you look at user_choice you will find that it is "1" which means its a string. Your choices are to compare it to a string =="1" or make it a number on intput return int(answer)

Eumel
  • 1,298
  • 1
  • 9
  • 19