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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started