Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HI I need help with this homework in Python and there are just Java examples Imp

ID: 3693841 • Letter: H

Question

HI I need help with this homework in Python and there are just Java examples Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code. Define the constructor such that an object can be created in one of two ways: with an apartment number or without. Supply a print method that prints the address with the street on one line and the city, state, and postal code on the next line. Supply a method def comesBefore(self, other) that tests whether this address comes before other when compared by postal code.

Explanation / Answer

class Address:
def __init__(self,house_number=None,street_num=None,apartment_num=None,city=None,state=None,postal=None):
self.__house_number = house_number
self.__street_num = street_num
self.__apartment_num = apartment_num
self.__city = city
self.__state = state
self.__postal = postal

def __init__(self,house_number=None,street_num=None,city=None,state=None,postal=None):
self.__house_number = house_number
self.__street_num = street_num
self.__apartment_num = apartment_num
self.__city = city
self.__state = state
self.__postal = postal

def print(self):
print("Street is:",self.street_num)
print(" City: ",self.city,"State: ",self.state,"Postal Code: ",postal)

def comesBefore(self, other):
if self.postal < other.postal:
return self.postal
return other.postal