составить программу решающую следующую задачу:Вы покупаете товар,и у вас имеются купюры номиналом 10,50,100,1000 рублей.Наберите необходимую сумму товара в N рублей так,чтобы она состояла из минимального количества купюр
Ответы
Ответ дал:
0
На Python 2.X:
# coding: utf-8
notes = (10, 50, 100, 1000)
def in_notes(notes, num):
d = {}
m = num
for note in sorted(notes, reverse=True):
d[note], m = divmod(m, note)
return d
n = input("Введите сумму: ")
print "В купюрах:"
for note, count in sorted(in_notes(notes, n).iteritems()):
if count == 0:
continue
print "{}: x{}".format(note, count)
# coding: utf-8
notes = (10, 50, 100, 1000)
def in_notes(notes, num):
d = {}
m = num
for note in sorted(notes, reverse=True):
d[note], m = divmod(m, note)
return d
n = input("Введите сумму: ")
print "В купюрах:"
for note, count in sorted(in_notes(notes, n).iteritems()):
if count == 0:
continue
print "{}: x{}".format(note, count)
Вас заинтересует
2 года назад
2 года назад
7 лет назад
10 лет назад