So this simple program should just check for existing owners of a property, current owners, the sale price and a few other things. I just learned a bit of oop last night and I'm wondering if there is a way to ignore or skip over certain positional arguments and let them default to variables in the class instead.
So in my "house2" instance down below, this represents a house that was just currently built so it doesn't have any current owners or previous owners.
Instead of entering None for the values I don't have,(previous owners, current owners) is there away where I can say, "hey skip positional arguments 'current owners' and 'previous owners' and just use the variables within the class instead". That way it would save me from typing None for every value that doesn't exist.
So my instance would look like this instead:
house2 = houseStats('77 Book Worm St', 'Inner-City', 1, 1, '120000')
compared to this:
house2 = houseStats('77 Book Worm St', 'Inner-City', 1, None, None, 1, '120000')
Full block of code below:
# A simple program to get information of a house.
class houseStats:
# class variables to default to if there are no instance variables.
current_owner = 0
previous_owner = 0
forsale = 0
def __init__(self, address, area, houseAge, currentOwner, previousOwner, forSale, salePrice):
self.address = address
self.area = area
self.house_age = houseAge
self.current_owner = currentOwner
self.previous_owner = previousOwner
self.forsale = forSale
self.saleprice = salePrice
# Function to determine the house age
def houseage(self):
return f"This house is {self.house_age} years old"
# Function to determine whether the house is for sale and who sold it.
def sold(self):
if self.forsale is None:
print("House is currently not for sale..")
else:
print(f'House is currently for sale for ${int(self.saleprice)}')
house1 = houseStats('19 Galaxy Way', 'Suburbs', 5, 'Douglas Forword', None, 1, 10000)
house2 = houseStats('77 Book Worm St', 'Inner-City', 1, None, None, 1, '120000')
house1.sold()