BMI with exception handling python


BMI with exception handling python



I need help with this code I am trying to apply, a short time ago I ran a bmi calculator in index and now I am trying to update that code with exception handling. So far the portions don't give me errors they just run strangely together. For example, when it prompts "Enter the user's name or '0' to quit" it doesn't actually end the process it continues on to the exception process. Can someone help me write this more efficiently. here is my code this is updated, the issue I am specifically having now is the program is not terminating when the user enters '0':


def bmi_calculator():
end = False

print("Welcome to the BMI Calculator!")

while end == False:

user = input("Enter student's name or '0' to quit: ")
if user == "0":
print("end of report!")
end = True
else:
print("Lets gather your information,", user)
break

flag='yes'
while flag != 'no':
#Exception block for catching non integer inputs
try:
#Prompting user to input weight
weight = int(input('Enter your weight in pounds : '))
if weight == 0:
raise ValueError
except ValueError:
print ('Oops!! Kindly enter non-zero numbers only.')
flag = input('Do you want to try again? yes/no : ')
continue

try:
#Prompting user to input height
height = float(input('Enter your height in inches : '))
if height == 0:
raise ValueError
except ValueError:
print ('Oops!! Kindly enter non-zero numbers only.')
flag = input('Do you want to try again? yes/no : ')
continue

#Formula for calculating BMI
BMI = round(weight * 703/(height*height), 2)
return (BMI)
print(" Your bmi is:", bmi_calculator())





Try using pass instead of continue
– fredguth
Jul 1 at 16:55


pass


continue





while end == False has no indented block following so there is no looping code. You might want to put a while around the main module code after the defs?
– Nick
Jul 1 at 17:23



while end == False


while


def





the issue that I am having right now is that the code is not terminating when someone enters '0' I am about to post updated code
– Docrunner
Jul 1 at 17:29









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to make file upload 'Required' in Contact Form 7?

Rothschild family

amazon EC2 - How to make wp-config.php to writable?