프로그래머스 - LV.0 - 옷가게 할인 받기

박종일·2023년 8월 13일
0

프로그래머스 LV.0

목록 보기
35/46

나의 풀이

def solution(price):
    
    answer = 0
    if price >= 500000:
        answer = price * 0.8
    elif price >= 300000:
        answer = price * 0.9
    elif price >= 100000:
         answer = price * 0.95
    else:
         answer = price 
    
    return int(answer)

다른 풀이

def solution(price):
    discount_rates = {500000: 0.8, 300000: 0.9, 100000: 0.95, 0: 1}
    for discount_price, discount_rate in discount_rates.items():
        if price >= discount_price:
            return int(price * discount_rate)

할인 % 를 딕셔너리 자료구조로 풀어낸 python 다운 다른 풀이가 있었다.
정말 배울 것이 많다!

profile
존경하는 인물: 스토브리그 백승수 단장(남궁민)

0개의 댓글