Skip to content

Commit

Permalink
Create 2-1_Library.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jisunp04023 authored Oct 20, 2023
1 parent 4d8e46c commit caf1c64
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 2-1_Library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from abc import *

class Book(metaclass=ABCMeta):
@abstractmethod
def get_rental_price(self, day):
pass

class ComicBook(Book):
def get_rental_price(self, day):
cost = 500
day -= 2
if day > 0:
cost += 200*day
return cost

class Novel(Book):
def get_rental_price(self, day):
cost = 1000
day -= 3
if day > 0:
cost += 300*day
return cost

def solution(book_types, day):
books = []
for types in book_types:
if types == "comic":
books.append(ComicBook())
elif types == "novel":
books.append(Novel())
total_price = 0
for book in books:
total_price += book.get_rental_price(day)
return total_price


book_types = ["comic", "comic", "novel"]
day = 4
ret = solution(book_types, day)

print("solution 함수의 반환 값은", ret, "입니다.")

0 comments on commit caf1c64

Please sign in to comment.