缺少1个必需的位置参数错误Python 3.6.2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了缺少1个必需的位置参数错误Python 3.6.2相关的知识,希望对你有一定的参考价值。

这是我的部分程序的代码。我试图让用户输入以返回公寓类型,押金和租金金额。我已经包含了一些我的其他函数,以及给出错误的函数,用于上下文。我收到错误:TypeError:determineRent()缺少1个必需的位置参数:'furniture'我不确定我错过了什么....感谢您的帮助。

def getType():
    print ("<<<<<Apartment Rental Program>>>>>")
    print("       -----------------------")
    print("      Studio --------> 1")
    print("      One Bedroom ---> 2")
    print("      Two Bedroom ---> 3")
    print("      Exit Program --> 4")
    print()
    global choice
    choice= int(input("Enter the type of apartment you wish to rent (1-3 or 4 to exit the program):"))
    global kind
    if choice== 1:
            kind= 'Studio'
    elif choice== 2:
            kind= 'One-Bedroom'
    elif choice== 3:
            kind= 'Two-Bedroom'
    else:
            print("Thank you for inquiring about our apartments for rent!")
            exit()
    while (choice >4 or choice <1):
        print("Invalid apartment type....must be 1-4!")
        choice= int(input("Enter the type of apartment you wish to rent (1-3 or 4 to exit the program):  "))
    if (choice >=1 and choice <=3):
           furn= input("Do you want the apartment furnished (Y/N)?  ")

    global furniture
    def furniture(furn):
        if furn== 'y':
            furniture= 'Furnished'
        elif furn== 'Y':
            furniture= 'Furnished'
        elif furn== 'n':
            furniture= 'Unfurnished'
        elif furn== 'N':
            furniture= 'Unfurnished'
    return kind, furniture #return to function that called them

#use the apartment type and furniture to determine rent and deposit
def determineRent(kind, furniture):
    global rent
    global deposit
    def deposit(kind):
        if kind == 1:
            deposit= 400
        elif kind == 2:
            deposit= 500
        elif kind == 3:
            deposit= 600
    def rent(furniture):
        if (kind)== 1:
            if furniture== 'Furnished':
                        rent= 750
            elif furniture == 'Unfurnished':
                        rent= 600
        elif (kind) == 2:
            if furniture == 'Furnished':
                        rent= 900
            elif furniture == 'Unfurnished':
                        rent= 750
        elif (kind) == 3:
            if furniture == 'Furnished':
                        rent= 1025
            elif furniture == 'Unfurnished':
                        rent= 925
    return rent, deposit #return to the function that called them

#dislpay the users selections and deposit/rent amount based on selections
def displayRent(kind, furniture, rent, deposit):
    if (choice <=3 or choice >=1):
     print("Description:     ", determineRent(kind),determineRent(furniture))
     print("Deposit:         $",determineRent(deposit))
     print("Rent:            $",determineRent(rent))

main()
答案

问题是你的函数determineRent期望两个参数kindfurniture。你需要在调用函数时将它们一起传递,这样determineRent( kind, furniture)而不是单独传递它们。

我建议你在继续前进之前通过这个basic tutorial on functions

以上是关于缺少1个必需的位置参数错误Python 3.6.2的主要内容,如果未能解决你的问题,请参考以下文章

Python sklearn 线性回归错误:fit() 缺少 1 个必需的位置参数:'y'"

python缺少1个必需的位置参数[重复]

类中的错误-缺少1个必需的位置参数[关闭]

python 装饰器 TypeError 缺少 1 个必需的位置参数

为啥我收到错误:__init__() 缺少 1 个必需的位置参数?

dump() 缺少 1 个必需的位置参数:python json 中的“fp”