Skip to content

Instantly share code, notes, and snippets.

@sxslex
Last active January 29, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sxslex/211f04e7398864f47832dc08f9780b4e to your computer and use it in GitHub Desktop.
Save sxslex/211f04e7398864f47832dc08f9780b4e to your computer and use it in GitHub Desktop.
Troco
# -*- coding: utf-8 -*-
def notas_total(valor):
notas = [100, 50, 20, 10, 5, 2, 1]
totais = []
for idx, nota in enumerate(notas):
totais.append(0)
if valor > nota:
totais[idx] = int(valor / nota)
valor -= totais[idx] * nota
return notas, totais
numero = int(raw_input())
# numero = 11257
print('Entrada:\n{}\n'.format(numero))
notas, totais = notas_total(numero)
print('Saida:')
masc = '{} nota{} de R$ {},00'
for nota, total in zip(notas, totais):
if total:
print(masc.format(total, 's' if total > 1 else '', nota))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment