I can't get the return value from find_total()
function in DictionaryTest
class, when I iterate over channel_list
dictionary. Python interpreter gives me this error:
TypeError: 'int' object is not iterable
What did I do wrong in the code?
class DictionaryTest:
def __init__(self, dictionary):
self.dictionary = dictionary
def find_total(self):
total = 0
for channel_num, channel_det in self.dictionary:
total += channel_det['charge']
return total
channel_list = {1: {'name': 'Sony PIX', 'charge': 3},
2: {'name': 'Nat Geo Wild', 'charge': 6},
3: {'name': 'Sony SET', 'charge': 3},
4: {'name': 'HBO - Signature', 'charge': 25}}
user_2 = DictionaryTest(channel_list)
print(user_2.find_total())