我无法获得此代码来打印所需内容。我认为我的函数编码不正确

I'm not able to get this code to print what's needed. I think my functions are coded incorrectly

下面是我遇到问题的代码,我似乎无法打印所需内容并收到错误消息:

'non-empty format string passed to object.__format__'

这是代码,我的函数语句似乎有问题,它没有执行到最终的 displayAns 打印出通知 [=17 的最后一条语句=]他们是什么类型driver

def main():
    customerName = input('Name of the customer: ')

    customerAge = int(input('Age of the customer: '))

    customerViolations = int(input('Customer\'s number of traffice violations: '))

    price = calcPrice(customerAge, customerViolations)
    code = riskCode(customerViolations)
    displayAns(customerName, price, code)


def calcPrice(customerAge, customerViolations):
    if customerAge < 25:
        if customerViolations >= 4:
            calcPrice = 480
        if customerViolations == 3:
            calcPrice = 450
        if customerViolations == 2:
            calcPrice = 405
        if customerViolations == 1:
            calcPrice = 380
        if customerViolations == 0:
            calcPrice = 325
        if customerViolations < 0:
            calcPrice = 'Invalid Violations Entry'
    elif customerAge >= 25:
        if customerViolations >= 4:
            calcPrice = 410
        if customerViolations == 3:
            calcPrice = 390
        if customerViolations == 2:
            calcPrice = 365
        if customerViolations == 1:
            calcPrice = 315
        if customerViolations == 0:
            calcPrice = 275
        if customerViolations < 0:
            calcPrice = 'Invalid Age or Violations Entry'

def riskCode(customerViolations):
    if customerViolations >= 4:
        riskCode = 'High'
    if customerViolations == 3:
        riskCode = 'Moderate'
    if customerViolations == 2:
        riskCode = 'Moderate'
    if customerViolations == 1:
        riskCode = 'Low'
    if customerViolations == 0:
        riskCode = 'No'
    if customerViolations < 0:
        riskCode = 'Invalid Violations Entry'


def displayAns(customerName, price, code):
    print(customerName, ' as a ', code, 'risk driver, your insurance will cost $', format(price, '.2f'), sep = '')


main()
def calcPrice(customerAge, customerViolations):
    if customerAge < 25:
        if customerViolations >= 4:
            calcPrice = 480

您不会通过执行 function_name = value 从函数中 return 值。您需要使用 return 语句。

def calcPrice(customerAge, customerViolations):
    if customerAge < 25:
        if customerViolations >= 4:
            return 480
        if customerViolations == 3:
            return 450
        #etc
def main():
customerName = raw_input('Name of the customer: ')

customerAge = int(input('Age of the customer: '))

customerViolations = int(input('Customer\'s number of traffice violations: '))

price = calcPrice(customerAge, customerViolations)
code = riskCode(customerViolations)
displayAns(customerName, price, code)


def calcPrice(customerAge, customerViolations):
if customerAge < 25:
    if customerViolations >= 4:
        returncalcPrice = 480
    if customerViolations == 3:
        calcPrice = 450
    if customerViolations == 2:
        calcPrice = 405
    if customerViolations == 1:
        calcPrice = 380
    if customerViolations == 0:
        calcPrice = 325
    if customerViolations < 0:
        calcPrice = 'Invalid Violations Entry'
elif customerAge >= 25:
    if customerViolations >= 4:
        calcPrice = 410
    if customerViolations == 3:
        calcPrice = 390
    if customerViolations == 2:
        calcPrice = 365
    if customerViolations == 1:
        calcPrice = 315
    if customerViolations == 0:
        calcPrice = 275
    if customerViolations < 0:
        calcPrice = 'Invalid Age or Violations Entry'
def riskCode(customerViolations):
if customerViolations >= 4:
    return 'High'
if customerViolations == 3:
    return 'Moderate'
if customerViolations == 2:
    return 'Moderate'
if customerViolations == 1:
    return 'Low'
if customerViolations == 0:
    return 'No'
if customerViolations < 0:
    return 'Invalid Violations Entry'


def displayAns(customerName, price, code):
print(customerName, ' as a ', code, 'risk driver, your insurance will cost $',format((price), '.2'), ' ')


main()

这里。我认为固定。