class House:
def __init__(self, loc, h_type, d_type, pri, comp_year):
self.loc = loc
self.h_type = h_type
self.d_type = d_type
self.pri = pri
self.comp_year = comp_year
def show_detail(self):
print("{0} {1} {2} {3} {4}".format(self.loc, self.h_type, self.d_type, self.pri, self.comp_year))
h1 = House("강남", "아파트", "매매", "10억", "2010년")
h2 = House("마포", "오피스텔", "전세", "5억", "2007년")
h3 = House("송파", "빌라", "월세", "500/50", "2000년")
sell = []
sell.append(h1)
sell.append(h2)
sell.append(h3)
print("총 {0}대의 매물이 있습니다.".format(len(sell)))
for house in sell:
house.show_detail()
결과
총 3대의 매물이 있습니다.
강남 아파트 매매 10억 2010년
마포 오피스텔 전세 5억 2007년
송파 빌라 월세 500/50 2000년
show_detail 함수를 너무 복잡하게 생각해서 막혔지만, 그래도 80% 는 따라간 과제였다.