본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 9

반응형

Q>

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

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


A>

cart = [{'price':38000, 'qty':6}, {'price':20000, 'qty':4}, {'price':17900, 'qty':3}, {'price':17900, 'qty':5}]
price = '{0}원 x {1}개 -> 총 {2}원'
print(price.format(cart[0]['price'], cart[0]['qty'],
cart[0]['price'] * cart[0]['qty']))
print(price.format(cart[1]['price'], cart[1]['qty'],
cart[1]['price'] * cart[1]['qty']))
print(price.format(cart[2]['price'], cart[2]['qty'],
cart[2]['price'] * cart[2]['qty']))
print(price.format(cart[3]['price'], cart[3]['qty'],
cart[3]['price'] * cart[3]['qty']))


O>

38000원 x 6개 -> 총 228000원

20000원 x 4개 -> 총 80000원

17900원 x 3개 -> 총 53700원

17900원 x 5개 -> 총 89500원


Process finished with exit code 0


반응형

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

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 8  (0) 2019.03.16
Python Learn the basics Quiz 7  (0) 2019.03.16
Python Learn the basics Quiz 6  (0) 2019.03.16