0

I am convinced that my code is right. Yet I am not getting the right results for the following:

:( input of 0.41 yields output of 4

:( input of 0.15 yields output of 2

The code is below:

def main():
    i = get_right_int()
    
    count = 0
    
    while i >= 0.25:
        i = i - 0.25
        count+=1
    
    while i >= 0.10:
        i = i - 0.10
        count+=1
        
    while i >= 0.04:
        i = i - 0.04
        count+=1
    
    while i >= 0.01:
        i = i - 0.01
        count+=1
        
    print(count)
    
 

def get_right_int():
    while True:
        price = get_float("Price: ")
        if price>0:
            break
    return price
    
    
main()

What am I missing?

  • Nickles are 5 cents. And of course, float arithmetic isn't as precise as all that. – DinoCoderSaurus Jul 13 at 0:20

You must log in to answer this question.

Browse other questions tagged .