Skip to content
Snippets Groups Projects
Commit c2b7ff4a authored by Daniel Moix's avatar Daniel Moix
Browse files

Week 3 Lecture

parent 40c9c131
Branches
No related tags found
No related merge requests found
.DS_Store 0 → 100644
File added
File added
def func1(i):
return i + 2
def func2(i):
x = func1(i-1)
return x + 5
def func3(i):
if i <= 0:
return 0
else:
print(i)
func3(i // 2)
i = 14
a = func2(i)
func3(i)
\ No newline at end of file
print("Hello CS 171")
# age = int(input("Enter your age: "))
# if age >= 21 :
# print("Line 3 executed.")
# print("Line 4 also is conditional")
# print("This is because of indentation")
def weightToKg(pounds):
POUNDS_PER_KG = 0.453592
return pounds * POUNDS_PER_KG
def heightToMeters(feet, inches):
INCHES_PER_FOOT = 12
INCHES_PER_METER = 0.0254
totalInches = inches + feet * INCHES_PER_FOOT
return totalInches * INCHES_PER_METER
def calculateBMI(pounds, feet, inches):
kg = weightToKg(pounds)
meters = heightToMeters(feet, inches)
bmi = kg / (meters ** 2)
return bmi
def weightStatus(bmi):
if bmi < 18.5:
return "Underweight"
elif bmi <= 24.9:
return "Normal Weight"
elif bmi <= 29.9:
return "Over Weight"
else:
return "Obese"
print("Welcome to BMI Calculator")
validData = True
weight = float(input("Enter your weight in pounds: "))
if weight > 0 :
heightFeet = int(input("Enter your height (feet): "))
heightInches = int(input("Enter your height (inches): "))
if heightFeet < 0 or heightInches < 0:
print("Height entry invalid")
validData = False
else:
validData = False
print("Weight is too low.")
print("Calculation cannot be performed.")
if validData == True:
print("Entries were OK. We are clear to calculate.")
kg = weightToKg(weight)
print("Your weight in kg is", kg)
meters = heightToMeters(heightFeet, heightInches)
print("Your height in meters is", meters)
bmi = calculateBMI(weight, heightFeet, heightInches)
print("Your BMI is", bmi)
status = weightStatus(bmi)
print("In this case, the chart says you are", status)
else:
print("Entry errors. We cannot proceed")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment