나도 코딩 # Quiz8

sh_awtylol4·2022년 2월 10일
0

나도코딩 Python

목록 보기
4/4
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대의 매물이 있습니다.
강남 아파트 매매 102010년
마포 오피스텔 전세 52007년
송파 빌라 월세 500/50 2000

show_detail 함수를 너무 복잡하게 생각해서 막혔지만, 그래도 80% 는 따라간 과제였다.

profile
포기하는 그 순간이 바로 시합종료예요...

0개의 댓글