0

我不断收到该error消息,我很困惑,不知道如何解决它。

这是我写的:

job = {'fireman': 42600, 'programmer': 48700, 'clerk': 23000}

salary = float(job * 1.05 ** years_of_service)

return salary

问题:

def salary(job, years_of_service):

    '''(str, int) -> float

Return the salary (in dollars) of a person holding job for
years_of_service.

Each year, a person receives a 5% increase in salary over his/her previous
year. The starting salary for various jobs:

    fireman                                     $42 600
    programmer                                  $48 700
    clerk                                       $23 000

years_of_service will be at least 0.

>>> salary('clerk', 2)
25357.5
'''
4

1 回答 1

1

问题是您试图将整个字典相乘。您需要从字典中获得起薪。由于这些方面的东西

salaries = {'fireman': 42600, 'programmer': 48700, 'clerk': 23000}

def salary(job, years_of_service):
    return salaries[job] * (1.05 ** years_of_service)
于 2013-05-30T05:29:28.873 回答