为什么round(15.0)== 15.0是假的?

时间:2017-08-20 03:29:12

标签: python-2.7 debugging

  1. 输入4整数nx[0]x[1]x[2] 使用n = a*x[0] + b*x[1] + c*x[2]n<=4000maxi = a+b+c (a,b,c>=0)
  2. 当我使用n=3164x = [42, 430, 1309]时。答案必须是15.但为什么round(15.0)==15.0是假的?我在第17行尝试打印i, j, tf, ti, maxi时找到了它:

    x = [0, 0, 0]
    n, x[0], x[1], x[2] = map(float, raw_input().split())
    x.sort(reverse=True) #suppose x[0]>=x[1]>=x[2]
    maxi=0
    
    if x[2] == 1.0:
        print int(n)
    
    else:
        for i in range(int(n/x[0])+1):      #first loop to find a: a <= n/x[0]
            for j in range(int(n/x[1])+1):  #second loop to find b: b <= n/x[1]
                #used math to find equation I found:
                tf = float(i*(1.0-x[0]/x[2]) + j*(1.0-x[1]/x[2]) + n/x[2])
                ti = int(round(tf))
                if tf > n or tf <0:
                    break
    
                if ti==tf and ti >= maxi: #find satisfactory value
                    maxi = ti
    
                #print i, j, ti, tf, maxi
        print maxi
    

0 个答案:

没有答案