diff --git a/cs171/Lect04/bmi.py b/cs171/Lect04/bmi.py new file mode 100644 index 0000000000000000000000000000000000000000..d336961049c36d0aabedd761c05f8f09b0de31cd --- /dev/null +++ b/cs171/Lect04/bmi.py @@ -0,0 +1,39 @@ + + +def poundsToKg(pounds): + return pounds / 2.205 + +def feetAndInchesToMeters(feet, inches): + totalInches = feet * 12 + inches + return totalInches * 0.0254 + +# Caution: Weight in kg, height in meters +def calculateBMI(weight, height): + return weight / (height * height) + +def getBMICategory(bmi): + if bmi >= 30: + category = "Obese" + elif bmi >= 25: + category = "Overweight" + elif bmi >= 18.5: + category = "Normal Weight" + else: + category = "Underweight" + return category + +# TODO: Add try/except and conditions to make sure users +# enter valid values for height and weight + +weight = float(input("Enter weight in pounds: ")) +print("Next, you will enter you height in feet and inches, separately.") +feet = int(input("Enter feet part of height: ")) +inches = int(input("Enter inches part of height: ")) + +metricHeight = feetAndInchesToMeters(feet, inches) +metricWeight = poundsToKg(weight) +yourBMI = calculateBMI(metricWeight, metricHeight) + +category = getBMICategory(yourBMI) + +print(f"At {feet} feet and {inches} inches tall at a weight of {weight} pounds, your BMI is {yourBMI:.1f}, which is {category}.") \ No newline at end of file diff --git a/cs171/Lect04/hello4.py b/cs171/Lect04/hello4.py new file mode 100644 index 0000000000000000000000000000000000000000..08e7e8a52d59389731c03795bac9b0210a0bc51c --- /dev/null +++ b/cs171/Lect04/hello4.py @@ -0,0 +1,38 @@ +# print("Hello, Lecture 4") +# +# print("Goodbye") +# +# print(18 < 9) +# print('C' > 'A') +# + +# try: +# age = int(input("What's your age? ")) +# except Exception: +# print("That wasn't a valid age. You are now 0.") +# age = 0 +# +# if age <= 21: +# print("You are 21 or under.") +# +# cont = input("Do you wish to continue? (y/n)") +# +# print(cont == 'y') +# +# +# if cont[0].lower() == 'y': +# print("Great, please continue") +# else: +# print("Thanks for playing") +# +# +# print( "&" < "(" ) +# print(ord("&")) +# print(ord("(")) + +letter = input("Give me a letter: ").upper() +if letter == 'A' or letter == 'E' or letter == 'I' or letter == 'O' or letter == 'U': + print(f"{letter} is a vowel") + +if letter in ('A', 'E', 'I', 'O', 'U'): + print(f"{letter.upper()} is a vowel") diff --git a/cs171/Lect04/myGrade.py b/cs171/Lect04/myGrade.py new file mode 100644 index 0000000000000000000000000000000000000000..74bca4addcd376c57ed362802993f5af0fd173c2 --- /dev/null +++ b/cs171/Lect04/myGrade.py @@ -0,0 +1,45 @@ +numberGrade = int(input("Enter numeric course grade: ")) +# +# if numberGrade >= 97: +# print("Course grade: A+") +# elif ... +# +# +# +# +# +# # Another way +# +# numberGrade = int(input("Enter numeric course grade: ")) +# +# if numberGrade >= 97: +# letterGrade = "A+" +# elif ... + + +if numberGrade >= 97: + letterGrade = "A+" +elif numberGrade >= 93: + letterGrade = "A" +elif numberGrade >= 90: + letterGrade = "A-" +elif numberGrade >= 87: + letterGrade = "B+" +elif numberGrade >= 83: + letterGrade = "B" +elif numberGrade >= 80: + letterGrade = "B-" +elif numberGrade >= 77: + letterGrade = "C+" +elif numberGrade >= 73: + letterGrade = "C" +elif numberGrade >= 70: + letterGrade = "C-" +elif numberGrade >= 65: + letterGrade = "D+" +elif numberGrade >= 60: + letterGrade = "D" +else: + letterGrade = "F" + +print(f"Your grade is {letterGrade}") \ No newline at end of file diff --git a/cs172/Lect04/hello.py b/cs172/Lect04/hello.py new file mode 100644 index 0000000000000000000000000000000000000000..bcddf220f7e138bd089492a1a1e832caab18c4ca --- /dev/null +++ b/cs172/Lect04/hello.py @@ -0,0 +1,76 @@ +import math +from abc import ABC, abstractmethod + +class Shape(ABC): + + def __init__(self, name, color = "gray"): + self.__name = name + self.__color = color + + def getColor(self): + return self.__color + + def getName(self): + return self.__name + + @abstractmethod + def getArea(): + pass + + def __str__(self): + return f"A {self.__color} {self.__name}." + +class Circle(Shape): + + def __init__(self, radius, color = "gray"): + super().__init__("Circle", color) + self.__radius = radius + + + def getRaidus(self): + return self.__radius + + def getPerimeter(self): + return 2 * self.__radius * math.pi + + def getArea(self): + return math.pi * (self.__radius ** 2) + +class Rectangle(Shape): + + def __init__(self, width, height, color = "gray"): + super().__init__("Rectangle", color) + self.__width = width + self.__height = height + + def getWidth(self): + return self.__width + + def getHeight(self): + return self.__height + + def getPerimeter(self): + return (self.__width + self.__height) * 2 + + def getArea(self): + return self.__width * self.__height + + def __str__(self): + return super().__str__()[:-1] + " of area " + str(self.getArea()) + "." + +class Square(Shape): + + def __init__(self, side, color = "gray"): + super().__init__("Square", color) + self.__side = side + + def getArea(self): + pass + +myRect = Rectangle(20, 12, "Green") +print(myRect) + +myCircle = Circle(1, "Chartreuse") +print(myCircle.getArea()) + +mySquare = Square(10, "Purple")