Getting an error in my simple submenu

I have developed a very simple menu/submenu for an assignment in basic python. Most of my code is working, except I am at a loss on one error I am getting.

The error is when I enter into my BMI submenu, after the calculations are complete, I hit my key to return to the main menu…and I get an error message and the programme stops.
Error is: NameError: name ‘package’ is not defined.
But when I check my code, it looks right!!..any help would be so so appreciated
here is my code:

def menu():
print(“[1] Calculate body mass index BMI”)
print(“[2] Veiw membership cost”)
print(“[0] Exit the program.”)

menu()
option = int(input("Please enter your option: "))

while option != 0:
if option == 1:
Height = float(input('Please enter your height in meters: '))
Weight = float(input('Please enter your weight in kilograms: '))

    def BMI(Height, Weight):
            BMI = round(Weight/(Height**2),3)

            if (BMI < 18.5):
                    return 'Underweight', BMI
            elif (BMI >= 18.5 and BMI < 25):
                    return 'Normal', BMI
            elif (BMI >= 25 and BMI < 30):
                    return 'Overweight', BMI
            elif (BMI >= 30):
                    return 'Obese', BMI
    quote, BMI = BMI(Height, Weight)
    print('Your BMI is: {} and you are: {}'.format(BMI, quote))
    anykey=input("Enter any key to return to main menu: ")
    menu()

elif option == 2:
    def package():
            print("[1] Our BASIC membership package")
            print("[2] Our REGULAR membership package")
            print("[3] Our PREMIUM membership package")
            print("[4] Return to MAIN menu")
            print("[5] Exit the programme")

while True:
    package()
    option = int(input("Please enter your option: "))
    if option == 1:
        print("Our BASIC membership cost is $10 per week, which is a monthly cost of $43.30")
    elif option == 2:
        print("Our REGULAR membership cost is $15 per week, or $65 per month")
    elif option == 3:
        print("Our PREMIUM membership plan costs $20 per week, which is $86.60 per month")
    elif option == 4:
        print("Hold on 2 seconds, returning you to the MAIN menu......")
        menu()
        break
    elif option == 5:
        print("Thank you for using my menu programme.")
        quit()

    else:
        print("Invalid option, please select 0 to 3")
        
    anykey=input("Enter any key to return to membership menu: ")
    package()

                
else:
    print("Invalid option, please select 0 to 2")

print()        
menu()
option = int(input("Please enter your option: "))

print(“Thank you for using my menu programme.”)

Please wrap code in triple backticks to preserve the formatting:

```python
if True:
    print(''Hello world!')
```

From what I can see, I think the problem is that you’re defining the functions indented into the body of the if statements, which means that they are defined on when that if statement is run. If you haven’t run option 2 yet, package wouldn’t have been defined.

So should the def of package be placesd at prior to the if?

It’s normal to have the shebang and encoding lines, if there are any, at the top, then any import statements, then the functions, and finally the main program at the bottom.