Class 2 Reflection


Class 2 went more in depth into booleans (Tru and False). First, we were asked to write a statement that would print out true, then we were asked to make one that was false. Then, they went on to discuss some operations, such as and, or, and not. The and operation makes sure that both statements are true, therefore the entire statement will be true. If one is false or both are false, it will be false. The or operation makes sure that only one of the two statemenets are true. If one of them is true, then the entire statement is true. The not statement checks to see if the opposite is true.

Homework 1: 3 Students

class Student:
    total_grades = 0
    total_students = 0

    def __init__(self, name, grade):
        self.name = name
        self.grade = grade
        Student.total_grades += grade
        Student.total_students += 1

    @classmethod
    def averageGrade(cls):
        if cls.total_students == 0:
            return 0
        return cls.total_grades / cls.total_students

student1 = Student("Bob", 95)
student2 = Student("Amy", 91)
student3 = Student("Jay", 72)

average = Student.averageGrade()
print(f"Average Grade: {average}")

falseStatement = average > 90
print(str(falseStatement))

trueStatement = average < 95
print(str(trueStatement))

Homework 2: Weather

import random

degrees = random.randint(0, 110)

weather = ["stormy", "sunny", "rainy", "cloudy", "windy", "thundering", "hurricane", "tornado", "fogy", "blizzard"]
randomWeather = random.choice(weather)

if ((degrees < 20) and (randomWeather == "stormy")) :
    print("You can't go outside! It's " + str(degrees) + " degrees right now and it's stormy!")
elif (randomWeather == "hurricane") :
    print("You shouldn't go outside, there's a hurricane!")
elif (randomWeather == "tornado") :
    print("You shouldn't go outside, there's a tornado!")
elif (randomWeather == "blizzard") :
    print("There's a blizzard outside right now, brr!")
elif (degrees < 40 ) :
    print("It's very cold today! " + str(degrees) + " degrees today.")
elif (degrees > 95 ) :
    print("Today's gonna be really hot: " + str(degrees) + " degrees today.")
else :
    print("Today's weather: " + str(degrees) + " degrees and it's currently " + randomWeather + ".")