Question: python programming debug question def get_sum_metrics(predictions, metrics=[]): for i in range(3): metrics.append(lambda x: x + i) sum_metrics = 0 for metric in metrics: sum_metrics +=

python programming debug question

def get_sum_metrics(predictions, metrics=[]):

for i in range(3):

metrics.append(lambda x: x + i)

sum_metrics = 0

for metric in metrics:

sum_metrics += metric(predictions)

return sum_metrics

def main():

print(get_sum_metrics(0)) # Should be (0 + 0) + (0 + 1) + (0 + 2) = 3

print(get_sum_metrics(1)) # Should be (1 + 0) + (1 + 1) + (1 + 2) = 6

print(get_sum_metrics(2)) # Should be (2 + 0) + (2 + 1) + (2 + 2) = 9

print(get_sum_metrics(3, [lambda x: x])) # Should be (3) + (3 + 0) + (3 + 1) + (3 + 2) = 15

print(get_sum_metrics(0)) # Should be (0 + 0) + (0 + 1) + (0 + 2) = 3

print(get_sum_metrics(1)) # Should be (1 + 0) + (1 + 1) + (1 + 2) = 6

print(get_sum_metrics(2)) # Should be (2 + 0) + (2 + 1) + (2 + 2) = 9

if __name__ == "__main__":

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!