0

I want to create a program which can be used for an ATM. This is what I've made:

# 500, 20, 100, 50, 10, 5, 1
nrb = 0
i=0
j=0
bancnote = [500, 200, 100, 50, 10, 5, 1]
for i in range(7):
    print('b:',bancnote[i])
suma = int(input('Scrieti suma dorita: '))
while suma > 0:
    while j <= 6:
        if suma >= bancnote[j]:
            nrb +=1
            suma -=bancnote[j]
            print('Am scazut: ', bancnote[j])
            print('Ramas: ',suma)
            print("Bancnote: ",nrb)
            j=0

My counter for that loop can't be reset. What can I do?

6
  • Please post the code instead of the picture, easier for other people to copy across and work for a solution. Commented Jun 2, 2017 at 9:57
  • Your code should be provided as text and not image, so we can reproduce your problem Commented Jun 2, 2017 at 9:57
  • Put code here and let us know exactly which loop is causing problem.. Commented Jun 2, 2017 at 9:58
  • That's the code: # bancomat cu bancnote de: # 500, 20, 100, 50, 10, 5, 1 nrb = 0 i=0 j=0 bancnote = [500, 200, 100, 50, 10, 5, 1] for i in range(7): print('b:',bancnote[i]) suma = int(input('Scrieti suma dorita: ')) while suma > 0: while j <= 6: if suma >= bancnote[j]: nrb +=1 suma -=bancnote[j] print('Am scazut: ', bancnote[j]) print('Ramas: ',suma) print("Bancnote: ",nrb) j=0 Commented Jun 2, 2017 at 10:00
  • Sorry for text formatting... Commented Jun 2, 2017 at 10:00

3 Answers 3

1

(It is easier for me to understand the code as I can read the language as well)

What you forgot is to increment j, so your code will only look at the 500 bank note every time. Thus not trying to decrease other value from the sum.

Sign up to request clarification or add additional context in comments.

Comments

1

there is no increment in variable j . so the loop will remain as it is

Comments

0

Your indices are not really required by Python. Considering what I understood from the problem, the code should look similar to this:

note_values = (500, 200, 100, 50, 10, 5, 1)

def partition(value):
    result = []
    for note in note_values:
        whole, value = divmod(value, note)
        result.append(whole)
    return result

if __name__ == "__main__":
    value = int(input("Sum wanted: "))
    notes = partition(value)
    for number, value in zip(notes, note_values):
        if number != 0:
            print("{} note of {:3d}".format(number, value))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.