본문 바로가기
언어/Python중급

[Python 기초 알고리즘] 거스름돈 구하기

by ErrorMin 2022. 8. 9.

지폐 거스름돈을 구하는 알고리즘이다.

 

def calculate_change(payment, cost):
    # // 나누기 연산 후 소수점 이하의 수를 버리고, 정수 부분의 수만 구함

    wwon = payment - cost
    
    fifty_thousand = wwon // 50000
    ten_thousand = (wwon % 50000) // 10000
    five_thousend = (wwon % 10000) // 5000
    one_thousand = (wwon % 5000) // 1000
    
    print(f"50000원 지폐: {fifty_thousand}장")
    print(f"10000원 지폐: {ten_thousand}장")
    print(f"5000원 지폐: {five_thousend}장")
    print(f"1000원 지폐: {one_thousand}장")
# 테스트 

calculate_change(100000, 33000)
print()
calculate_change(500000, 378000)

 

'언어 > Python중급' 카테고리의 다른 글

[Python] yaml 파일을 활용한 python 코딩  (0) 2022.12.21
[Python-Django] 개발 환경 구성  (0) 2022.10.13