Homework:
Create a class.
Initialize three parameters in a parameterized constructor. However, include “just in case” default values in the header (see “Combining both types of constructors” in slides.)
Write one class variable.
Write an accessor method that prints the values of all attributes.
Write a modifier method for each attribute.
Can we change class variables with our usual modifier method?
Recourses:
Class slides:https://docs.google.com/presentation/d/14oVru9bDjB9n1JAjho_T3defWE8aU1Evin1JPFeOdnI/edit?usp=sharing
Class code: https://replit.com/join/zwdsmkhhom-shrav816
Contact Info:
shravyassathish@gmail.com (mentor)
kingericwu@gmail.com (TA)
felixguo41@gmail.com (TA)
def __init__(self, name, age, address):
self.name = name
self.age = age
self.address = address
def changeName(self, newName):
self.name = newName
p1 = MyClass("Juandale Pringle", "Very Old Years Old", "123 Quandale Dingle Avenue")
print(p1.name)
print(p1.age)
print(p1.address)
p1.changeName("Johnny")
print("new name: " + p1.name)
p1.name = "Andrew"
print("new name one more time: " + p1.name)
class Class:
def __init__(self, t="LoL", s=0, a=0.0):
self.teacher = t
self.size = s
self.avgMark = a
subject = "Python"
def getInfo(self):
if self.teacher[:-1] == "s":
print(f"The average mark of {self.teacher}' ", end="")
else:
print(f"The average mark of {self.teacher}'s ", end="")
print(f"class of size {self.size} is {self.avgMark}.")
def setTeacher(self, newTeacher):
self.teacher = newTeacher
def setSize(self, newSize):
self.size = newSize
def setAvgMark(self, newAvgMark):
self.avgMark = newAvgMark
current = Class()
current.getInfo()
current.setTeacher("Shravya")
current.setSize(15)
current.setAvgMark(3.5)
current.getInfo()
other = Class("Chris", 1, 4.0)
other.getInfo()