1
\$\begingroup\$

This is a follow-up of the old BMI Calculator that I previously wrote. I read a majority of the feedback that you guys gave and I would like to thank you all for the kind comments. Here is the link. BMI Revised version. Please do another favor which is to screen through the codes below again.

These are the codes that I wrote and try to improve.

def to_start():
    while True:
        try:
            _start = input("Press Y to begin")
        except ValueError:
            continue
        else:
            if _start in ("Y", "y"):
                print("Let's begin")
                return _BMI()
            else:
                print("Invalid input")
                continue


def _BMI():
    while True:
        try:
            weight = float(input("Please enter your weight(kg): "))
            weight_confirm = input("Y to confirm. N to re-enter: ")
        except ValueError:
            continue
        else:
            if weight_confirm in ("Y","y"):
                break
            else:
                continue
    while True:
        try:
            height = float(input("Please enter your height(m): "))
            height_confirm = input("Y to confirm. N to re-enter: ")
        except ValueError:
            continue
        else:
            if height_confirm in ("Y","y"):
                index = (float(weight/(height*height)))
                if 18.5 <= index <= 22.9:
                    print("Low Risk")
                elif 23 <= index <= 27.4:
                    print("Moderate Risk")
                else:
                    print("High Risk")
                break
            else:
                continue


to_start()
\$\endgroup\$
  • \$\begingroup\$ How does user stop the program? Because now it will loop forever in to_start untill the user gives up and decides to start again \$\endgroup\$ – Ludisposed Jul 12 '17 at 12:54
  • \$\begingroup\$ There is no link to last question, previous question \$\endgroup\$ – Ludisposed Jul 12 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.