How to fix program that calculates minimum amount of coins in change : I have a homework assignment in which we have to write a program that outputs the change to be given by a vending machine using the lowest number of coins. E.g. £3.67 can be dispensed as 1x£2 + 1x£1 + 1x50p + 1x10p + 1x5p + 1x2p.

However, my program is outputting the wrong numbers. I know there will probably be rounding issues, but I think the current issue is to do with my method of coding this.

    change=float(input("Input change"))
    
    twocount=0
    onecount=0
    halfcount=0
    pttwocount=0
    ptonecount=0
    
    while change!=0:
         if change-2>-1:
              change=change-2
              twocount+=1
         else:
              if change-1>-1:
                   change=change-1
                   onecount+=1
              else:
                   if change-0.5>-1:
                        change=change-0.5
                        halfcount+=1
                   else:
                        if change-0.2>-1:
                             change=change-0.2
                             pttwocount+=1
                        else:
                             if change-0.1>-1:
                                  change=change-0.1
                                  ptonecount+=1
                             else:
                                  break
    
    print(twocount,onecount,halfcount,pttwocount,ptonecount)
RESULTS:

    Input: 2.3
    Output: 11010
    i.e. 3.2
    
    Input: 3.2
    Output:20010
    i.e. 4.2
    
    Input: 2
    Output: 10001
    i.e. 2.1