问题重复4次,浮动不可调用,代码错误

时间:2017-09-10 15:47:09

标签: python floating-point

我不明白为什么代码不起作用,他们已经向我重复了4次问题。并说浮动不可调用。我已经尝试这样做了很长一段时间,但我似乎什么也得不到。是否有更容易的方式python3?我刚刚在两周前学会了这门语言。对我而言,这不是一个全新的世界,而是我不熟悉的许多事物。例如缩进

def get_taxi_info():
        flag_down = float(input("What's the flag-down fare: $"))
        within = float(input("What's the rate per 400 meters within 9.8km? $"))
        beyond = float(input("What's the rate per 350 meters beyond 9.8km? $"))
        distance = float(input("What's the distance traveled (in meters)? "))
        peak = input("Is the ride during a peak period? [yes/no]")
        mid6 = input("Is the ride between midnight and 6am? [yes/no]")
        location = input("Is there any location surcharge? [yes/no]")
        surloca = float(input("What's the amount of location surcharge?"))
        return (flag_down, within, beyond, distance, peak == 'yes', mid6 == 'yes', location == 'yes', surloca)

    def calculate_taxi_fare():
        dist = get_taxi_info()
        if dist[3] > 9800:
            extra = (dist[3] - 9800) % 350
            if extra == 0:
                a = (extra//350) + 22
            else:
                a = (extra//350) + 23
            return a
        elif dist[3] <= 9800:
            extra = (dist[3] - 1000) % 400
            if extra == 0:
                a = (extra//400)
            else:
                a = (extra//400) + 1
            return a

    def peakornot():
        peak = get_taxi_info()
        if peak[4] == True and peak[5] == False:
            surcharge = 1.25
            return surcharge
        elif peak[4] == False and peak[5] == True:
            surcharge = 1.50
            return surcharge

    taxifare = calculate_taxi_fare()
    info = get_taxi_info()
    peak1 = peakornot()
    taxifare = calculate_taxi_fare()
    if info[6] == True:
        payable = ((info[0] + (info[1] * taxifare()) + (info[2] * taxifare())) * peak1[0]) + info[7]
        print ("The total fare is $" + str(payable))
    elif info[6] == False:
        payable = ((info[0] + (info[1] * taxifare()) + (info[2] * taxifare())) * peak1[0]) + info[7]
        print ("The total fare is $" + str(payable))

1 个答案:

答案 0 :(得分:2)

函数calculate_taxi_fare返回float,因此此行taxifarefloat

taxifare = calculate_taxi_fare()

因此你不能说taxifare()因为它看起来像是一个函数调用,所以你可以使用例如

info[1] * taxifare