Python不会打印表达式

时间:2016-09-08 15:59:42

标签: python printing

所以,我对编程很新,并且一直在尝试使用Python。我正在做一个非常简单的程序,将usd转换为欧元。

这是我正在尝试解决的问题的文本

  

你要前往法国。你需要将美元兑换成欧元(   欧盟货币)。有两个货币兑换摊位。每个人都有   显示CR的显示:他们的转换率为每美元欧元和他们的费用   百分比。这笔费用是在你转换资金之前收取的。哪个展位会给   你最贵的欧元,多少欧元,差价是多少。   例1:   美元:200   CR1:0.78   费用:1(金额152.88欧元)   CR2:0.80   费用:3(金额155.2欧元)   答案:2是最好的;差价是2.32欧元; 155.2欧元

这是我的代码

    from __future__ import division

usd = int(input("How much in USD? "))
cr1 = int(input("What is the convertion rate of the first one? "))
fee1 = int(input("What is the fee of the first one? "))

cr2 = int(input("What is the convertion rate of the second one? "))
fee2 = int(input("What is the fee of the second one? "))

def convertion (usd, cr, fee):
    usdwfee = usd - fee
    convert = usdwfee * cr
    return convert

first = convertion(usd, cr1, fee1)
second = convertion(usd, cr2, fee2)

fs = first - second
sf = second - first

def ifstatements (first,second,fs,sf):
    if first < second:
        print "1 is the best; difference is ",fs," euroes. 2 converts to ",first," euroes."
    elif first > second:
        print "2 is the best; difference is",sf," euroes. 2 converts to", second," euroes."

ifstatements(first, second, fs, sf)

问题在于,当我运行程序时,它不会打印出来。它只需要我输入并且不输出任何内容。

1 个答案:

答案 0 :(得分:1)

更多地检查你的逻辑。

usd = float(input("How much in USD? ")) cr1 = float(input("What is the convertion rate of the first one? ")) fee1 = float(input("What is the fee of the first one? ")) cr2 = float(input("What is the convertion rate of the second one? ")) fee2 = float(input("What is the fee of the second one? "))

您的转化率为int。与在Integer中一样,这意味着它不能有浮点(您的示例中的小数“CR1:0.78”)。如果将其转换为int,则cr1将变为0。同时也改变你的美元和费用以接受浮动,因为我假设你也想要处理美分

所以改变:

{{1}}

它应该有效。