I want to know how to get Python back to the options!

Asked 2 years ago, Updated 2 years ago, 18 views

Hello! I posted the wrong question earlier, correct it again, and upload the question.

I'm working on a program that calculates BMI and BMR in Python As you can see in the picture, there are options from 1 to 4. (Please don't worry about the wrong number of entries between 3 and 4 in the middle menu!) If the user presses the wrong option, I want to mark it as Invalid and return to the option.

I would appreciate it if you could tell me how to code. I've been learning Python for about two weeks, so there are many things I don't know. ㅠ<

+) Modify and upload the code. There are many things I don't know because I'm posting my first question. I'm sorry for the immature question.

def inputDetails():

    print("Introduction and Welcome Message\n")
    print("Please input your details below : ")
    user_name = input("Name : ")
    user_birthday = input("Year of birth (YYYY) : ")
    user_gender = input("Gender [F/M] : ")
    weight = eval(input("Weight (kg) : "))
    height = eval(input("Height   (m) : "))

def menu():

    print("\nChoose your option below:")
    print ("1 - Body Mass Index (BMI) Calculator")
    print ("2 - Basal Metabolic Rate (BMR) Calculator")
    print ("3 - Weight Management")

    print ("4 - Reset user details")
    print ("Q/q - Quit")
    choice = input("Your choice? ")

    if choice == "1":
         bmiCalculator()
    elif choice == "2": 
        bmr()
    elif choice == "q, Q":
        exit()
    else :
        print("\nInvalid Choice! Please select from the list of choices.\n")

inputDetails()
menu()

python

2022-09-22 14:25

1 Answers

You can repeat it indefinitely with while True in the def menu,

When calling the menu() itself

while True: menu()

This is how the menu () itself operates indefinitely.


2022-09-22 14:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.