파이썬
웅앵
4년 전
조회 3,897
어느 과일가게에서 사은 행사를 하고 있다. 상품 가격은 각각 사과=2000원, 배= 4000원, 참외=2500원, 딸기 한 상자 =8000원이다. 구매 총액에 따라 사은 행사 기준을 달리하고 있는데 총구매액이 10000원 이상이면 사과 한 개 추가, 20000원 이상이면 참외 한 개 추가, 30000원 이상이면 배 한 개 추가, 40000원 이상이면 딸기 한 상자를 사은품으로 준다고 한다. 이때 소비자로부터 상품의 구매 개수를 입력받아 소비자가 지불하여야 할 총지불액을 구하고 최종 받게되는 사과, 배, 참외, 딸기 개수를 출력하는 프로그램을 작성하여라.
이거 파이썬으로 어떻게 하시는지 아시는 분 도움 좀 주세요ㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
4년 전
….
예외 처리는 생략합니다.
질문에 주어진 내용 그대로 처리하는 과정입니다.
간단하니까 그대로 복사&붙여넣기하지 말고,
이해 후 응용&활용하길 바라며 이만 줄입니다.
</p>
<p>APPLE_PRICE = 2000
PEAR_PRICE = 4000
MELON_PRICE = 2500 # oriental melon, korean melon
STRAWBERRY_PRICE = 8000</p>
<p> </p>
<p>apple_quantity = int(input("How many apples? "))
pear_quantity = int(input("How many pears? "))
melon_quantity = int(input("How many melons? "))
strawberry_quantity = int(input("How many strawberries? "))</p>
<p> </p>
<p>total_price = 0
total_price += APPLE_PRICE * apple_quantity
total_price += PEAR_PRICE * pear_quantity
total_price += MELON_PRICE * melon_quantity
total_price += STRAWBERRY_PRICE * strawberry_quantity</p>
<p> </p>
<p>if total_price >= 10000: apple_quantity += 1
if total_price >= 20000: melon_quantity += 1
if total_price >= 30000: pear_quantity += 1
if total_price >= 40000: strawberry_quantity += 1</p>
<p> </p>
<p>print("==============================")
print("Total price : %s" % "{:,}".format(total_price))
print("apple : %s" % "{:,}".format(apple_quantity))
print("pear : %s" % "{:,}".format(pear_quantity))
print("melon : %s" % "{:,}".format(melon_quantity))
print("strawberry : %s" % "{:,}".format(strawberry_quantity))</p>
<p>
</p>
<p>How many apples? 1
How many pears? 1
How many melons? 1
How many strawberries? 1
====================
Total price : 16,500
apple : 2
pear : 1
melon : 1
strawberry : 1</p>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
B
BiHon
4년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
예) 사과만 20개(40,000) 사면, 사은품으로 딸기 한 박스만 추가.
[code]
if total_price >= 40000: strawberry_quantity += 1
elif total_price >= 30000: pear_quantity += 1
elif total_price >= 20000: melon_quantity += 1
elif total_price >= 10000: apple_quantity += 1
[/code]