728x90
나의 코드
def solution(price):
if price >= 500000:
return int(price*0.8)
elif price >= 300000 and price < 500000:
return int(price * 0.9)
elif price >= 100000 and price < 300000:
return int(price * 0.95)
else:
return int(price)
.
.
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)
다른 분의 코드
깔끔 그 자체인 코드..
728x90
'CodingTest > [프로그래머스 LV.0]' 카테고리의 다른 글
프로그래머스 LV.0 - 순서쌍의 개수[Python] (1) | 2023.01.21 |
---|---|
프로그래머스 LV.0 - 배열의 유사도[Python] (0) | 2023.01.21 |
프로그래머스 LV.0 - 중앙값 구하기[Python] (0) | 2023.01.21 |
프로그래머스 LV.0 - 두 수의 나눗셈[Python] (0) | 2023.01.20 |
프로그래머스 LV.0 - 두 수의 합[Python] (0) | 2023.01.20 |