Decompose the value of a ballot in Python

1

I need to read an integer value and calculate the smallest number of possible banknotes in which the value can be decomposed. The grades considered are 100, 50, 20, 10, 5, 2 and 1.

And dps print the read value and then the minimum amount of notes of each type needed.

EXAMPLE:

  • input

576

  • output

R $ 576

5 rating (s) of $ 100.00

1 rating (s) of $ 50.00

1 note (s) of R $ 20.00

0 rating (s) of $ 10.00

1 rating (s) of $ 5.00

0 rating (s) of $ 2.00

1 rating (s) of $ 1.00

    
asked by anonymous 12.08.2017 / 22:15

1 answer

1

I think this will solve, as python was not specified I used python 2.7 but this can easily be converted to 3.x

N = int(input()) 

notas = [100.00,50.00,20.00,10.00,5.00,2.00,1.00]
print ("R$ %d:"%(N))
for x in notas:
    print ("%i nota(s) de R$ %.2f"%((N/x),x))
    N %= (x)

Edit: The multiplication and on account of the division of python which can round off slightly differently for floats, I have better arranged for integers

Edit2: Code for python 3.x

Edit3: I had forgotten the actual 1 note

Edit4: Using commas instead of dot would look like this:

N = int(input()) 

notas = [100,50,20,10,5,2,1]
print ("R$ %d:"%(N))
for x in notas:
    print ("%i nota(s) de R$ %d,00"%((N/x),x))
    N %= (x)
    
12.08.2017 / 23:30