TypeError:PrintLists()获取0个位置参数,但给出了2个

时间:2017-11-10 15:14:46

标签: python

这是我的错误消息:

TypeError: PrintLists() takes 0 positional arguments but 2 were given

输出应如下所示:

欢迎来到Botany Bay家居销售计算器 该计划将计算房屋的平均售价 去年卖了。然后它将确定上面卖出的房屋数量 平均而言,平均售出的房屋数量最多,价格最高 家和最低价的家。

=============================================== ======================== Botany Bay Home Sales

平均售价为:119221.29美元

高于平均水平的房屋数量为:3

低于平均水平的房屋数量为:4

最畅销的房子是:$ 155249.00所属地:Beufort

最低卖房价为:85000.00美元所有者:Swanson

代码:

def PrintMessage():
#Welcome Message
    print("Welcome to the Botany Bay home sales calculator")
    print("This program will calculate the average selling price of the homes")
    print("sold this past year. It will then determine how many homes sold above")
    print("the average, how many homes sold below the average, the highest priced")
    print("home and the lowest priced home.")
    print("=======================================================================")
    return


def PrintLists():
#declare local variables
    Prices = ['125900', '115000', '105900', '85000', '150000', '155249', '97500']
    HomeOwners = ['Carson','Smith','Jackson','Swanson','Perry','Beufort', 'Anderson']

    print("Botany Bay Home Sales")
    print("*********************************")

    average = DetermineAverage(Prices)
    AboveBelowAvg(Prices, average)
    DetermineHighest(Prices, HomeOwners)
    DetermineLowest(Prices, HomeOwners)

    print()


def DetermineAverage(Prices):
    average = 0.0
    sum1 = 0.0
    for i in range(len(Prices)):
        sum1 += float(Prices[i])
    #Print average
    average = sum1/len(Prices)
    print("The average selling price is: $%.2f" % average)
    return average

def AboveBelowAvg(Prices, average):
#print the number of homes sold above and below the average
    NumAbove = 0
    NumBelow = 0

    for i in range(len(Prices)):
        if float(Prices[i]) > average:
            NumAbove += 1
        if float(Prices[i]) < average:
            NumBelow += 1

    print("The number of homes selling above average are: ", NumAbove)
    print("The number of homes selling below average are: ", NumBelow)

def DetermineHighest(Prices, HomeOwners):
#Determine Highest priced home and home owner
    highvalue = int(Prices[0])
    index = 0

    for i in range(1,len(Prices)):
        if (int(Prices[i]) > highvalue):
            highvalue = int(Prices[i])
            index = i

#print out highest value and the owner of that house
    print("The highest selling house was: $%.2f\tOwned by: %s" % (highvalue, HomeOwners[index]))

def DetermineLowest(Prices, HomeOwners):
    lowvalue = int(Prices[0])
    index = 0
    for i in range(1,len(Prices)):
        if (int(Prices[i]) < lowvalue):
            lowvalue = int(Prices[i])
            index = i

#print out lowest value and the owner of that house
    print("The lowest selling house was: $%.2f\t\tOwned by: %s" % (lowvalue, HomeOwners[index]))

PrintMessage()
PrintLists()

1 个答案:

答案 0 :(得分:0)

您可以将所有内容整合在一起。你只需要在每个句子的末尾放一个\n,你想休息一下。 编辑: 我刚测试了你的代码,但没有收到任何错误。