-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBMICalculator.py
36 lines (31 loc) · 1.02 KB
/
BMICalculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# BMI Calculator
# Method used for numeric Input Validation
def checkInt(num):
# Loop through input to validate data
while True:
# Try to convert num to int
try:
num = int(num)
# if num greater than 0
# then break and reurn num as an int
if num > 0:
break
# else prompt user to enter a num greater than 0
else:
num = input("Please enter number greater than zero: ")
# if try fails catch error
# and prompt user to enter a number and not a str
except ValueError:
print("This is not an int!")
num = input("Please enter number greater than zero and not a letter: ")
# output and return the rentalPeriod
return int(num)
height = checkInt(input("What is your height in cm? "))
weight = checkInt(input("What is your weight in kg? "))
height = height * .01
bmi = weight / height ** 2
print("\n\tBMI Calculator")
print("\t==============")
print("This is your height: " + str(height))
print("This is your weight: " + str(weight))
print("This is your bmi: " + str(bmi))