Please improve me

QUES:

1. Prompt the user “Enter your weight (in kgs)” and record weight

2. Prompt the user “What is your preferred unit of height? Type “F” for feet and “M” for meters”

and record the preference

3. If user says “F” then prompt user "You will enter your height given as feet and inches. First

enter feet" and record feet and then prompt user “Now enter inches” and record inches

4. If user says “M” then prompt user “What is your height in meters” and record height in

meters

5. If user had chosen “F” then convert height into meters

6. Compute BMI using the following formula ctrl+ / for comment

7. Depending on the value of BMI, report the user’s type given by the following table:

● BMI < 18.5 : UNDERWEIGHT

● 18.5 <= BMI < 25 : NORMAL

● 25 <= BMI < 30 : OVERWEIGHT

● BMI > 30 : VERY-OVERWEIGHT

SOL:

def input_single_float(prompt):
ret=float(input(prompt))
return ret
weight=input_single_float("enter your weight in kg ")
height_unit=input("what is your preferred unit of height ")

if height_unit==“F”:
feet= input_single_float("please enter both feet and ")
inches=input_single_float("now enter inches ")
meters=(feet + inches/12)*0.3048
elif height_unit==“M”:
meters=input_single_float(“please enter your height in meters”)
else:
print(‘KINDLY TYPE “F” OR “M”’)

WHAT SHOULD I WRITE HERE SO THAT AFTER TYPING ANY OTHER INPUT EXCEPT M OR F MY PROGRAM DONOT EXECUTES FURTHER.

height=meters
bmi=weight/height**2
print("your BMI is ", bmi)

if bmi<18.5:
print(“you are underweight, please consult doctor”)
elif bmi<25:
print(“you are normal, please great going”)
elif bmi<30:
print(“you are overweight, watch out”)
else:
print(“you are very overweight, please consult doctor”)

Hello,

Should you try while loop? Use while loop , iterate the loop until user enter’s F or M. But you need to add step to clear the prompt statements inside the while loop.

Hope it helps.

Thanks