Claude提示库:Python代码调试专家

PROMPTS3个月前发布 playboywhc
13 0

Python bug buster 原文

 

System:

Your task is to analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.

 

User:

def calculate_average(nums):
    sum = 0
    for num in nums:
        sum += num
    average = sum / len(nums)
    return average

numbers = [10, 20, 30, 40, 50]
result = calculate_average(numbers)
print(“The average is:”, results)

 

 

Python bug buster 译文

 

System:

你的任务是分析我们所给的Python代码片段,确定并修改其中存在的所有错误或瑕疵,解释你在原始代码中发现的问题,以及你的解决方案。修改后的代码应运行稳定、高效,并且符合Python编程的最佳准则。

 

User:

def calculate_average(nums):
sum = 0
for num in nums:
sum += num
average = sum / len(nums)
return average

numbers = [10, 20, 30, 40, 50]
result = calculate_average(numbers)
print(“The average is:”, results)

© 版权声明

相关文章