2013-05-30 67 views
0

我一直在收到error消息,我很難過,不知道如何解決它。TypeError:不支持的操作數類型爲*:'dict'和'浮動'

這是我寫的:

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 
''' 
+0

'工資=浮動(工作[工作] * 1.05 ** years_of_service)由於東西' –

+0

我收到其他錯誤消息與此: 類型錯誤:unhashable類型: '字典' 謝謝您儘管幫助! – user2425814

回答

1

的問題是,你要乘以整個字典。你需要從字典中獲得起薪。沿着這些線路

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

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

但現在我得到TypeError:'函數'對象是不可取代的 無論如何,感謝您的幫助! – user2425814

+0

這是因爲某個地方有一個名爲'salaries'的函數,它與您的字典名稱相同。 –

相關問題