500error
[COS Pro 2급, Python] 3차 5번 : 여행객의 총 교통비 구하기 본문
반응형
여행객들의 총 교통비를 계산하려고 합니다. 교통편은 "Bus", "Ship", "Airplane" 총 3가지입니다. 나이가 20살 이상이면 어른 요금을, 그렇지 않으면 어린이 요금을 받습니다. 각 교통편별 가격은 다음과 같습니다.
어른 | 어린이 | |
Bus | 40,000원 | 15,000원 |
Ship | 30,000원 | 13,000원 |
Airplane | 70,000원 |
45,000원 |
여행객들이 10명 이상인 경우 연령에 따라 할인을 받습니다.
어른 | 어린이 |
10% | 20% |
여행객들의 나이를 담고 있는 배열 member_age와 member_age의 길이 member_age_len, 교통편인 transportation이 매개변수로 주어질 때, 총 교통비를 return 하도록 solution 함수를 작성하려 합니다. 빈칸을 채워 전체 코드를 완성해주세요.
code
def solution(member_age, transportation):
if transportation == 'Bus':
adult_expense = 40000
child_expense = 15000
elif transportation == 'Ship':
adult_expense = 30000
child_expense = 13000
elif transportation == 'Airplane':
adult_expense = 70000
child_expense = 45000
if len(member_age) >= 10:
adult_expense = int(adult_expense * 9 / 10)
child_expense = int(child_expense * 8 / 10)
total_expenses = 0
for age in member_age:
if age >= 20 :
total_expenses += adult_expense
else:
total_expenses += child_expense
return total_expenses
member_age1 = [13, 33, 45, 11, 20]
transportation1 = "Bus"
ret1 = solution(member_age1, transportation1)
print("solution 함수의 반환 값은", int(ret1), "입니다.")
member_age2 = [25, 11, 27, 56, 7, 19, 52, 31, 77, 8]
transportation2 = "Ship"
ret2 = solution(member_age2, transportation2)
print("solution 함수의 반환 값은", int(ret2), "입니다.")
반응형
'알고리즘 > 파이썬' 카테고리의 다른 글
[COS Pro 2급, Python] 3차 7번 : 남은 재료로 주스 만들기 (0) | 2024.01.03 |
---|---|
[COS Pro 2급, Python] 3차 6번 : 타일 색칠 방법 구하기 (0) | 2024.01.03 |
[COS Pro 2급, Python] 3차 4번 : 단어의 오타 수정하기 (1) | 2024.01.03 |
[COS Pro 2급, Python] 3차 3번 : 체조 선수의 점수 구해주기 (0) | 2024.01.03 |
[COS Pro 2급, Python] 3차 2번 : 장학생 수 구하기 (1) | 2024.01.03 |
Comments