def main(): valid_choice = False while (valid_choice == False): choice, valid_choice = user_prompt(' ') if (choice == "1"): calculate_bmi() elif (choice == "2"): calculate_retirement() print() print("----------------------------------------") print() main()
def bmi(): form = BMIForm() if form.validate_on_submit(): height_ft = int(request.form['height_ft']) height_in = int(request.form['height_in']) weight = int(request.form['weight']) bmi = calculate_bmi(height_ft, height_in, weight) category = get_category(bmi) return render_template('bmiresults.html', title='BMI Results', bmi=bmi, category=category) return render_template('bmi.html', title='BMI Calculator', form=form)
if w == -1: print('wartosc nieprawidlowa') else: break else: w = float(weight) break print(w) height = input("Podaj wzrost w m: ") try: float(height) except ValueError as e: h = fix_units(height, 'm') if h == -1: print('wartosc nieprawidlowa') else: h = float(height) print(h) result_bmi = bmi.calculate_bmi(w, h) state = bmi.get_state(result_bmi) print(state) filename = state.lower() + '.txt' with open(filename) as fopen: tip = fopen.read() print(tip)
def test_bmi(): BMI = bmi.calculate_bmi(70.7, 172.7) assert BMI == 23.704715025402944
import bmi # podaj wagę i wrost weight = float(input("Podaj wagę w kg: ")) height = float(input("Podaj wzrost w m: ")) # wyślij wagę i wzrost do funkcji obliczjącej result_bmi = bmi.calculate_bmi(weight, height) state = bmi.get_state(result_bmi) print(state) filename = state.lower() + '.txt' with open(filename) as fopen: tip = fopen.read() print(tip)
except ValueError: print("That is not a valid number please try again.\n") while True: try: height_in = int(input("Inches: ")) break except ValueError: print("That is not a valid number please try again.\n") while True: try: weight = int(input("\nEnter your weight in pounds: ")) break except ValueError: print("That is not a valid number please try again.") bmi_value = bmi.calculate_bmi(height_ft, height_in, weight) category = bmi.get_category(bmi_value) print("\nBMI: " + str(bmi_value) + "\n" + "Category: " + category) if choice == 2: print("\n" + 30 * '-') print(" Retirement") print(30 * '-' + "\n") while True: try: age = int(input("Enter your age: ")) break except ValueError: print("That is not a valid number please try again.\n")
def test_calc_bmi(self): self.assertEqual(bmi.calculate_bmi(6, 0, 150), 20.83) self.assertEqual(bmi.calculate_bmi(5, 3, 125), 22.68)
def test_for_the_tallest(self): actual = calculate_bmi(dictionary_people_list=dictionary_people_list_tallest) expected = "Please enter a valid height" self.assertEqual(actual, expected, "Failed for validation for height")
def test_for_less_than_heaviest_weight(self): actual = calculate_bmi(dictionary_people_list=dictionary_people_list_heaviest_weight) expected = "Please enter a valid weight" self.assertEqual(actual, expected, "Failed for validation for weight")
from bmi import calculate_bmi from bmr import calculate_bmr # Execution starts from here print("\n-------------Welcome Fitness Calculator--------------") print("\n--------------Enter Your Choice----------------------") print("\n 1. BMI ") print("\n 2. BMR ") print("\n 3. EXIT ") choice = int(input().strip()) weight = float(input("Enter your weight in kg: ")) height = float(input("Enter your height in cm: ")) if choice == 1: BMI = calculate_bmi(weight, height) print("BMI:" + str(BMI)) elif choice == 2: age = int(input("Enter your age in years: ").strip()) gender = input("Are you male? (M/F): ").strip() BMR = calculate_bmr(weight, height, age, gender) print("BMR:" + str(BMR)) else: quit()
def test_exception(): with pytest.raises(ZeroDivisionError): calculate_bmi(70, 0)
def test_calculate_bmi(): result = calculate_bmi(70, 1.8) assert result == 21.604938271604937