I want to finish number 1 and 2 in Python so that I can do number 3.

Asked 2 years ago, Updated 2 years ago, 23 views

There are 1, 2, 3, 4 choices in the menu function I want to use calculators 1 and 2, but I don't know which code to use. If you look at the code, I want to make it impossible to use Weight Management number 3 without using the BMI calculator and BMR calculator.

In the main function, write c_select = 0 c_select2 = 0 #2. From elif to ifc_select = '1' Can I write ifc_select2 = '2' in number 3?

def main():
user_name, user_birthday, user_gender, weight, height = inputDetails()
bmiCalculator(weight, height)
choice = menu()
while choice not in ['q', 'Q']:
    if choice == "1":
       bmiValue = bmiCalculator(weight, height)
    elif choice == "2":
       bmr()
    elif choice == "3":
        weightManagement()
    elif choice == "4":
        user_name, user_birthday, user_gender, weight, height = inputDetails()
        print("\nInvalid Choice! Please select from the list of choices.\n")

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) : "))
    return user_name, user_birthday, user_gender, weight, height

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?")
return choice


def bmiCalculator(weight, height):
    bmiValue = (height*height/weight)
    print(bmiValue)
    return bmiValue

main()

python

2022-09-21 14:37

1 Answers

I think you can add a flag to check if you called when you called No. 1 and No. 2, and check when you call No. 3.

...
if choice == "1":
    flag_bmi = True
elif choice == "2":
    flag_bmr = True
elif choice == "3":
    if flag_bmi && flag_bmr:
        weightManagement()
...


2022-09-21 14:37

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.