'The code is saying that i have a "TypeError: int() can't convert non-string with explicit base" .How can i fix that?Here is my code sorry if it is bad

from collections import namedtuple

BeltStats = namedtuple('BeltStats', 'score ninjas')

ninja_belts = {'yellow': BeltStats(50, 11),
               'orange': BeltStats(100, 7),
               'green': BeltStats(175, 1),
               'blue': BeltStats(250, 5)}


def get_total_points(belts=ninja_belts):
    total_scores = []
    
    for i in belts:
        total_scores.append(int(belts[i].score,belts[i].ninjas))
    
    return sum(total_scores)
    
get_total_points()


Solution 1:[1]

The problem is with the second argument that you are passing to int(). The second argument must be a valid base value and it defaults to base 10.

I think your intention here is to just add up the scores. Hence the correct code will be

from collections import namedtuple

BeltStats = namedtuple('BeltStats', 'score ninjas')

ninja_belts = {'yellow': BeltStats(50, 11), 'orange': BeltStats(100, 7), 'green': BeltStats(175, 1), 'blue': BeltStats(250, 5)}

def get_total_points(belts=ninja_belts):
    total_scores = []
    for i in belts:
        total_scores.append(int(belts[i].score))

    return sum(total_scores)
print(get_total_points())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gopal_hegde