Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 ( 1 5 marks ) For this task, you are to re - write the given program ( BMI Program ) to make
Task marks
For this task, you are to rewrite the given program BMI Program to make it more robust by raising exceptions upon invalid inputs and handling the raised exceptions.
BMI Program
def calculateBMI weight heightInCM:
height heightInCM
return weight height
def main:
weight int input Enter the weight in :
heightInCM int inputEnter your height in cm:
bmi calculateBMI weight heightIncM;
printBMI: : formatbmi
if bmi :
printThe person is underweight"
elif bmi :
print The person's weight is in the normal range"
else:
printThe person is overweight"
main
Instructions
The program calculates the BMI body mass index of a person. A user can keyin 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 ifcondition to handle invalid inputs or results.
You must use EAFP principle only
You must use try, except and raise statements concepts
Your Solution
Dont use if else condition
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started