TypeError:*:'dict'和'float'的不支持的操作数类型

时间:2013-05-30 05:26:12

标签: python python-3.x

我继续收到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
'''

1 个答案:

答案 0 :(得分:1)

问题在于你试图乘以整个字典。你需要从dict获得起薪。由于这些方面的原因

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

def salary(job, years_of_service):
    return salaries[job] * (1.05 ** years_of_service)