lundi 14 novembre 2016

Error in Python Function assignment

Basically i have to call my function stringMenu and it will set off other functions depending on what number the user inputted, funcChoice. Right now the error it is giving me is UnboundLocalError: local variable 'funcChoice' referenced before assignment. However, I did assign it to the integer of zero in the second line of my code? Any help would be greatly appreciated. I am using Python 3

print("Please indicate your choice of functionality by entering its asssociated number.")
funcChoice = int(0)

while funcChoice != 4:

    def stringMenu():
        if (funcChoice == 1):
            #calls other functions

        elif funcChoice == 2:
            #do stuff

        elif funcChoice == 3:
            #do stuff

        else:
            print("Thank you for using my program! Have a nice day!")

    while ((funcChoice <= 0) or (funcChoice >= 5)):
        print("\n1.    Find the length of a string")
        print("2.    Find the middle characters of a string")
        print("3.    Enter a list of strings and receive back a single string!")
        print("4.    Quit")
        funcChoice = int(input("Your choice:"))

    stringMenu()

Aucun commentaire:

Enregistrer un commentaire