0

Trying to solve pset1 cash less comfortale with python.

Whats my mistake as I cant figure it out.

Lets say I add 5.16 as cash owed that is 20*0.25+1*0.1 +1*0.05 +1*0.01 , 23 coins total used.

while True:
    x=float(input("Enter a number:"))
    x=x*100
    if not x<0:
        break
x=int(x)
coins= x/25+(x%25)/10+((x%25)%10)/5+((x%25)%10)%5
print(int(coins))

And this gives an answer of 24 not 23. Why?

1

Python 3 uses // for integer division, and / for floating point division, instead of deciding based on the operand types (which frequently led to confusion, since unlike C you won't necessarily know the type of a value at compile time).

So use // here instead of /.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .