Python货币转换器

时间:2018-02-11 06:50:29

标签: python

以下代码是简单的货币转换器。一切正常但最后的if语句会导致代码中断。每当我在if语句中输入小于.25的数字时,它就会破坏代码。我非常感谢为什么会这样做。非常感谢你。

def currency_converter(amount):
        hundred = 0
        fifty = 0
        ten = 0
        five = 0
        one = 0
        quarter = 0
        dime = 0
        while amount > 0:
                if amount >= 100:
                        hundred+=1
                        amount-=100
                if 100 > amount >= 50:
                        fifty+=1
                        amount-=50
                if 50 > amount >= 10:
                        ten+=1
                        amount-=10
                if 10 > amount >= 5:
                        five+=1
                        amount-=5
                if 5 > amount >= 1:
                        one+=1
                        amount-=1
                if 1 > amount >= float(.25):
                        quarter+=1
                        amount-=float(.25)
                if float(.25) > amount >= float(.1):
                        dime+=1
                        amount-=float(.1)
        print(hundred, "Hundred-dollar bill")
        print(fifty, "Fifty-dollar bill")
        print(ten, "Ten-dollar bill")
        print(five, "Five-dollar bill")
        print(one, "One-dollar bill")
        print(quarter, "Quarter")      
        print(dime, "Dime")
currency_converter(5.6)

1 个答案:

答案 0 :(得分:0)

$ node server.js