Write a program to find the minimum number of notes required for the amount M. Available note denominations are 500, 50, 10, 1.
Given
M = 1543, it can be written as1543 = 3*(500) + 3*(50) + 0*(10) + 1*(3)Then the output should be
500: 3 50: 0 10: 4 1: 3
sample input=1543 output is 500: 3 50: 0 10: 4 1: 3
sample input is=1259 and output is 500: 2 50: 5 10: 0 1: 9
def change(amount):
nominals = [500, 50, 10, 1]
d = {}
for nominal in nominals:
n = 0
while amount >= nominal:
amount -= nominal
n += 1
d[nominal] = n
return d
def print_change(d):
for nominal in sorted(d, reverse=True) :
print(f'{nominal}: {d[nominal]}', end=' ' )
print()
def main():
n = int(input())
d = change(n)
print_change(d)
if __name__ == '__main__':
main()
Comments
Leave a comment