def bmi(): form = BMIForm() if form.validate_on_submit(): BMI.DoBMI(form.footField.data, form.inchesField.data, form.poundsField.data) ret = BMI.BMI(form.footField.data, form.inchesField.data, form.poundsField.data) flash(ret) return render_template('bmi.html', title='Calculate BMI', form=form)
def inner(): try: self.result = BMI.calculate(copy.copy(a), copy.copy(b)) self.resultReturned = True except: self.runtime = True self.eobj = sys.exc_info()[0:2]
def promt_for_BMI(): feet = prompt_user("Please enter your height in feet", '^[0-8]$') inches = prompt_user("Please enter your height in inches", '^[0-9]+$') pounds = prompt_user("Please enter your weight in pounds", '\d*\.\d+|\d+') try: return BMI(int(feet), int(inches), float(pounds)) except RuntimeError as e: print(e) return ''
def main(): print("What feature do you want to use?") print("1. BMI") print("2. Retirement") choice = input("Choose: ") while choice != "1" or choice != "2": choice = input("Choose: ") if choice == "1": weight = input("Enter weight:") feet = input("Enter feet:") inches = input("Enter Inches:") int_weight = int(weight) int_feet = int(feet) int_inches = int(inches) s = BMI.BMI(weight, feet, inches) value = s.BMI_calculator(int_weight, int_feet, int_inches) print(value) status = s.BMI_category(value) print(status) if choice == "2": age = input("Enter age: ") salary = input("Enter salary: ") percentage_saved = input("Enter Percentage of salary Saved: ") goal = input("Retirement goal: ") int_age = int(age) int_salary = int(salary) int_percent = int(percentage_saved) int_goal = int(goal) t = retirement.retirement(int_age, int_salary, int_percent, int_goal) yearly_savings = t.annual_savings(int_salary, int_percent) goal = t.retirement_calculator(yearly_savings, int_age, int_goal)
def test_BMI_pounds_raises_exception_on_non_float_args_for_None(): with pytest.raises(TypeError): BMI(5,9,None)
def test_BMI_inches_raises_exception_on_negative_int_args(): with pytest.raises(RuntimeError): BMI(5,-1,15.2)
def test_BMI_inches_raises_exception_on_incorrect_int_args(): with pytest.raises(RuntimeError): BMI(5,12,15.2)
def test_BMI_inches_raises_exception_on_non_int_args_for_None(): with pytest.raises(TypeError): BMI(5,None,15.2)
def main(): weight = 75.0 height = 1.75 bmi_val = BMI.bmi(weight,height) # BMIモジュールのbmi()関数呼び出し print(bmi_val)
def test_BMI_returns_string_argument(): result = BMI(5,8,150.0) assert isinstance(result,str), 'Test Failed: BMI function failed to return a valid string result'
def test_BMI_feet_raises_exception_on_improbable_int_args(): with pytest.raises(RuntimeError): BMI(50,11,15.2)
def retrieveBMI(): return render_template('Results.html', entries=BMI.retrieveEntry())
def bmi(height_feet, height_inches, weight): BMI.BMI(height_feet, height_inches, weight) return 'Request Accepted'
def main(): masa = float(input("Podaj swoją wagę (w kilogramach): \n")) wzrost = float(input("Podaj swój wzrost (w metrach): \n")) BMI = bmi.calc_bmi(masa, wzrost) bmi_status = bmi.bmi_status(BMI) advice(bmi_status)
from BMI import * test1 = BMI(74, 140) test2 = BMI(74, 141) test3 = BMI(70, 155) test4 = BMI(68, 160) test5 = BMI(69, 166) test6 = BMI(64, 170) test7 = BMI(65, 176) print(test1) print(test2) print(test3) print(test4) print(test5) print(test6) print(test7)
def test_BMI_pounds_raises_exception_on_negative_float_args(): with pytest.raises(RuntimeError): BMI(5,10,-1.0)
def test_BMI_pounds_raises_exception_on_incorrect_float_args(): with pytest.raises(RuntimeError): BMI(5,0,.0)
def test_BMI_inches_raises_exception_on_non_int_args_for_str(): with pytest.raises(TypeError): BMI(5,"inches",15.2)
def test_BMI_feet_raises_exception_on_non_int_args_for_float(): with pytest.raises(TypeError): BMI(122.2,11,15.2)
def test_BMI_inches_raises_exception_on_non_int_args_for_float(): with pytest.raises(TypeError): BMI(5,15.4,15.2)
def test_BMI_feet_raises_exception_on_non_int_args_for_str(): with pytest.raises(TypeError): BMI("feet",11,15.2)
choice = input(">") if int(choice) == 1: print("How tall are you? (in feet and inches. e.g. 5 11)") height = input(">") #splitting the height into feet and inches height = height.split(" ") height_feet = height[0] height_inches = height[1] print("What is your weight? (in pounds. e.g. 200)") weight = input(">") print("Your BMI is " + BMI.BMI(height_feet, height_inches, weight)) elif int(choice) == 2: print("What is your current age?") age = input(">") print("What is your annual salary?") salary = input(">") print( "What percentage of your salary do you save? (Input as a percentage not a decimal)" ) saving = input(">") print("How much money do you want to have by the time you retire?") goal = input(">") print("Retirement age:\n", Retirement.retirement(age, salary, saving, goal))