본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 12

반응형

Q>

장바구니 내역을 딕셔너리에 원소로 갖는 리스트로 정의하고 합계금액 / 총 금액을 출력하시오.

장바구니 내역 : 38000원 6개 / 20000원 4개 / 17900원 3개 / 17900원 5개


A>

price_dic = {'price1':38000, 'price2':20000, 'price3':17900, 'price4':17900}
count_dic = {'qty1':6, 'qty2':4, 'qty3':3, 'qty4':5}

result_list1 = []
result_list2 = []

for v1 in price_dic.values():
a = result_list1.append(v1)
for v2 in count_dic.values():
b = result_list2.append(v2)

count = 0

for v1, v2 in zip(result_list1, result_list2):
mul = v1 * v2
print('{}원 x {}개 -> {}원'.format(v1, v2, mul))
count += mul

print('-' * 30)
print('총 합계 금액 -> {}원'.format(count))


O>

38000원 x 6개 -> 228000원

20000원 x 4개 -> 80000원

17900원 x 3개 -> 53700원

17900원 x 5개 -> 89500원

------------------------------

총 합계 금액 -> 451200원


Process finished with exit code 0

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 14  (0) 2019.03.27
Python Learn the basics Quiz 13  (0) 2019.03.18
Python Learn the basics Quiz 11  (0) 2019.03.18
Python Learn the basics Quiz 10  (0) 2019.03.18
Python Learn the basics Quiz 9  (0) 2019.03.16