Rounding up with pennies in Python?

后端 未结 5 1761
夕颜
夕颜 2020-12-19 20:46

I am making a change program in python. The user must input a dollar amount and then the program will calculate the change in twenties, tens, fives, ones, quarters, dimes, n

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 21:51

    Multiply the user's inputed dollar value by 100, convert to int, and work in units of pennies.

    Integer arithmetic is dead simple (and exact). Floating point arithmetic is tricky and forces you to use more brain cells :) . Save brain cells and work entirely in ints.

提交回复
热议问题