Class 7 Reflection


In Class 7 we learned about procedures. A procedure is a group of programming instructions. There are 2 main types of procedures, a procedure that returns a value of data and a procedure that executes a block of statements. They demonstrated to us how they created a procedure. First you define the name of the procedure, then you set the parameters. Then within the procedure, you create the code that is executed when the procedure is ran. They then demonstrated how we could use procedures to define objects and sort them into classes. If this object with the given perameters fits this condition, this object is now part of this class. I think this class was very easy to understand, and they explained it very well.

Homework 1:

# HW Hack 1

def updateNumber(currentNumber, chosenNumber):
    if currentNumber < chosenNumber:
        currentNumber = chosenNumber
        return currentNumber
    
currentNumber = 12
chosenNumber = 45
newNumber = updateNumber(currentNumber, chosenNumber)
print(newNumber)

Homework 2:

# HW Hack 2

class young:
    name = ""
    age = 0

class old:
    name = ""
    age = 0

def classifyPerson(name, age):
    if age > 50:
        oldPerson = old()
        oldPerson.name = name
        oldPerson.age = age
        return oldPerson
    else:
        youngPerson = young()
        youngPerson.name = name
        youngPerson.age = age
        return youngPerson

person1 = classifyPerson("Johnny", 23)
person2 = classifyPerson("Ariana", 38)
person3 = classifyPerson("Tom", 61)
person4 = classifyPerson("Bethany", 84)

print(f"{person1.name} is {person1.age}")
print(f"{person2.name} is {person2.age}")
print(f"{person3.name} is {person3.age}")
print(f"{person4.name} is {person4.age}")