Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
973 Lượt xem

if contract.wage > 33333 :

    result = float(6396+(contract.wage - 33333)*0.25)


gives me error :

TypeError("float() argument must be a string or a real number, not 'NoneType'") 

can anyone help me?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

The error message you're encountering suggests that contract.wage might be None in some cases, causing the float() function to fail. To address this issue, you should check if contract.wage is not None before attempting to perform calculations with it. Here's how you can modify your code to handle this:

if contract.wage is not None and contract.wage > 33333: result = float(6396 + (contract.wage - 33333) * 0.25) else: # Handle the case when contract.wage is None or less than or equal to 33333 result = 0 # Or any other default value you want to assign 


Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

@Mohamed

if contract.wage is not None and contract.wage > 33333: 

​result = float(6396 + (contract.wage - 33333) * 0.25) 

else: 

​result = 0

Hope this will help you

Ảnh đại diện
Huỷ bỏ