diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..912edaf3d516c18ef0069f900487cfdf3c25d8cd Binary files /dev/null and b/.DS_Store differ diff --git a/cs171/.DS_Store b/cs171/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b3898b5425616f75f1171aa795d0f49dcd349002 Binary files /dev/null and b/cs171/.DS_Store differ diff --git a/cs171/Lect03/ch5.py b/cs171/Lect03/ch5.py new file mode 100644 index 0000000000000000000000000000000000000000..edf0579bb2aa3975e7c5aee74bf2930413127fe8 --- /dev/null +++ b/cs171/Lect03/ch5.py @@ -0,0 +1,19 @@ + + +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 diff --git a/cs171/Lect03/hello.py b/cs171/Lect03/hello.py index 061448a8d1383c3b10b99d3b4667be38bd953c3a..0a54a464c5633acc87d55834a8137fa02b09b777 100644 --- a/cs171/Lect03/hello.py +++ b/cs171/Lect03/hello.py @@ -1 +1,63 @@ -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