Created
October 16, 2015 04:45
-
-
Save nesffer/2b0d85200c567fc64f32 to your computer and use it in GitHub Desktop.
[Python] 자판기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from sys import exit | |
pay = int(input("투입할 금액을 입력하세요: ")) | |
price = int(input("제품의 가격을 입력하세요: ")) | |
number = int(input("제품의 갯수를 입력하세요: ")) | |
coin = int(input("동전의 단위를 입력하세요: ")) | |
coin_list = [500, 100, coin] | |
coin_list.sort(reverse=True) | |
if pay >= price * number: | |
back = pay - price * number | |
else: | |
print("투입된 금액이 부족합니다.") | |
exit() | |
for i in range(3): | |
if back != 0: | |
share = int(back / coin_list[i]) | |
back = back - coin_list[i] * share | |
print(coin_list[i], "원", share, "개") | |
five = int(back / coin) | |
one = int((back % coin) / 100) | |
print("반환:", str(back) + "원") | |
print("오백원:", str(five) + "개", "백원:", str(one) + "개") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment