Python question

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

n=int(input)

nnn=1000-n

count=0
while nnn>0:
    nnn=nnn%500
    count+=nnn//500
    nnn%=100
    count+=nnn//100
    nnn=nnn%50
    count+=nnn//50
    nnn%=10
    count+=nnn//10
    nnn=nnn%5
    count+=nnn//5
    nnn%=1
    count+=nnn//1
    if nnn==0:
        break

I wonder why the while door doesn't work here

I know the answer is that using the for statement is better

I wonder why the door doesn't work

N = int(input())
rest = 1000 - N
moneys = [500, 100, 50, 10, 5, 1]
result = 0

for money in moneys:
    if rest == 0:
        break

    result += rest // money
    rest %= money

print(result)

python

2022-09-20 10:49

1 Answers

n=int(input) --> n=int(input())


2022-09-20 10:49

If you have any answers or tips


© 2022 pinfo. All rights reserved.