Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this task, you are to re - write the given program ( BMI Program ) to make it more robust by raising exceptions upon

For this task, you are to re-write the given program (BMI Program) to make it more robust by raising exceptions upon invalid inputs and handling the raised exceptions. def calculateBMI(weight, heightInCM): height = heightInCM /100 return weight / height **2 def main(): weight = int(input("Enter the weight in kg: ")) heightInCM = int(input("Enter your height in cm: ")) bmi = calculateBMI(weight, heightInCM); print("BMI: {:.2f}".format(bmi)) if bmi <18.5: print("The person is underweight") elif bmi <=25: print("The person's weight is in the normal range") else: print("The person is overweight") main() Instructions The program calculates the BMI (body mass index) of a person. A user can key-in invalid inputs, which causes the program to crash. Your task is to handle the invalid inputs and results using exception handling concepts. Requirements To achieve full marks for this task, you must follow the instructions above when writing your solution. Additionally, your solution must adhere to the following requirements: The program must handle all invalid inputs or results. You must not use if-condition to handle invalid inputs or results. You must use EAFP principle only You must use try,
except and raise statements concepts. Don't use if else conditions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions