카테고리 없음

dict를 이용하여 각 품목별, 가격 , 수량을 입력하여 총 지불액을 알아보는 방법 파이썬

LeeJinSol 2019. 6. 6. 22:03
728x90

shopping = dict()

while True:
    item = input("구매 품목 : ")

    if item =="":
        break

    price = int(input("가격 : "))
    num = int(input("개수 : "))

    if item in shopping:
        print("이미 구매한 품목입니다.")
    else:
        shopping[item] = [price, num, price*num]

total =0

for key,value in shopping.items():
    print("%s %d원 x %d 개 = %d원 "%(key,value[0],value[1],value[2]))
    total = total +value[2]

print("총지불액"  ,total)      

728x90