#돈을 냈을 때, 5만원, 1만원, 5천원, 1천원의 지폐의 합이 최소가 되도록 거스름돈을 알려주는 예제
#payment=내가 내는 돈, cost=상품의 가격
#함수 정의
def calculate_change(payment, cost):
change = payment - cost
fifty_thousand = int(change / 50000)
change = change % 50000
ten_thousand = int(change / 10000)
change = change % 10000
five_thousand = int(change / 5000)
change = change % 5000
one_thousand = int(change / 1000)
print("거스름돈은 다음과 같습니다")
print() #공백
print("50000원짜리 지폐 : " + str(fifty_thousand) + "장")
print("10000원짜리 지폐 : " + str(ten_thousand) + "장")
print("5000원짜리 지폐 : " + str(five_thousand) + "장")
print("1000원짜리 지폐 : " + str(one_thousand )+ "장")
#100,000원을 내고 54,000원짜리 상품을 구매할 때 받는 거스름돈
calculate_change(100000, 54000)
#다른 방법으로 함수 정의하기
def calculate_change(payment, cost):
change_money = payment - cost
fifty_thousands = change_money//50000
ten_thousands = (change_money - fifty_thousands*50000)//10000
five_thousands = (change_money - fifty_thousands*50000 - ten_thousands*10000)//5000
thousands = (change_money - fifty_thousands*50000 - ten_thousands*10000 - five_thousands*5000)//1000
print("50000원 지폐: " + str(fifty_thousands) + "장")
print("10000원 지폐: " + str(ten_thousands) + "장")
print("5000원 지폐: " + str(five_thousands) + "장")
print("1000원 지폐: " + str(thousands) + "장")