Do not understand the error in function

I have just started using python and I am doing this function exercise but I don’t understand the error. As budget is an argument of int type. I am not sure why it gives me type erroe tuple and int not supported.

Write your over_budget function here:

def over_budget(budget,food_bill,electricity_bill,internet_bill,rent):
sum=food_bill+electricity_bill,internet_bill+rent
if (budget<(sum)):
return True
else:
return False

print(over_budget(100, 20, 30, 10, 40))

print(over_budget(80, 20, 30, 10, 30))

Error
Traceback (most recent call last):
File “script.py”, line 9, in
print(over_budget(100, 20, 30, 10, 40))
File “script.py”, line 4, in over_budget
if (budget<(sum)):
TypeError: ‘<’ not supported between instances of ‘int’ and ‘tuple’

sum=food_bill+electricity_bill,internet_bill+rent

You have a comma between electricity_bill and internet_bill instead of the addition operator.
So, sum ends up being a tuple containing two values (the first value being food_bill+electricity_bill and the second value being internet_bill+rent)

budget is an integer while sum ends up being a tuple. Therefore the comparison (budget < sum) raises a TypeError exception in Python 3+

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.