🔍 문제
유아 : 18000원 / 소아 : 25000원 / 어른 : 50000원 / 할인 혜택 대상에게 할인 50% 일 때
가격 영수증을 출력
🗝 사용함수
format(n, ',') : 3째 자리에서 쉼표. ex) 25,000
🖥 실행
|
childPrice = 18000
infantPrice = 25000
adultPrice = 50000
d = 0.5
def fNum(n):
return format(n, ',')
def totalPrice(c1, c2, i1, i2, a1, a2):
cp = c1 * childPrice
cp_dc = int(c2 * childPrice * d)
print(f'유아 {c1}명 요금: {fNum(cp)}원')
print(f'유아 할인 대상 {c2}명 요금: {fNum(cp_dc)}원')
ip = i1 * infantPrice
ip_dc = int(i2 * infantPrice * d)
print(f'소아 {i1}명 요금: {fNum(ip)}원')
print(f'소아 할인 대상 {i2}명 요금: {fNum(ip_dc)}원')
ap = a1 * adultPrice
ap_dc = int(a2 * adultPrice * d)
print(f'성인 {a1}명 요금: {fNum(ap)}원')
print(f'성인 할인 대상 {a2}명 요금: {fNum(ap_dc)}원')
print('='*30)
print(f'Total:{c1+c2+i1+i2+a1+a2}명')
print(f'Total Price: {fNum(cp+ip+ap+cp_dc+ip_dc+ap_dc)}원')
print('='*30)
ch1 = int(input('유아 입력:'))
ch2 = int(input('할인 대상 입력:'))
if1 = int(input('아이 입력:'))
if2 = int(input('할인 대상 입력:'))
ad1 = int(input('어른 입력:'))
ad2 = int(input('할인 대상 입력:'))
print('='*30)
totalPrice(ch1, ch2, if1, if2, ad1 ,ad2)
|
cs |
📝 결과물
'Coding test > Python 기초문제' 카테고리의 다른 글
[함수] 등차수열, 등비수열 계산기 (0) | 2022.04.29 |
---|---|
[함수] 단리, 복리 계산기 (0) | 2022.04.29 |
[함수] 속도, 시간 계산기 (0) | 2022.04.28 |
[함수] 계산기 만들기 (0) | 2022.04.28 |
[예외 처리] 비밀번호 확인 프로그램 (0) | 2022.04.28 |