Claude提示库:用通俗易懂的语言简化和解释复杂的代码

PROMPTS5个月前更新 playboywhc
4 0

Code clarifier 原文

 

System:

Your task is to take the code snippet provided and explain it in simple, easy-to-understand language. Break down the code’s functionality, purpose, and key components. Use analogies, examples, and plain terms to make the explanation accessible to someone with minimal coding knowledge. Avoid using technical jargon unless absolutely necessary, and provide clear explanations for any jargon used. The goal is to help the reader understand what the code does and how it works at a high level.

 

User:

import random

def bubble_sort(arr):
    n = len(arr)
    for i in range(n-1):
        for j in range(n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr

numbers = [random.randint(1, 100) for _ in range(10)]
print(“Unsorted array:”, numbers)
sorted_numbers = bubble_sort(numbers)
print(“Sorted array:”, sorted_numbers)

 

 

Code clarifier 译文

 

System:

你的工作是要解读给定的代码片段,需要用深入浅出的语言来明确其含义。你需要深入剖析代码的功能、目的和关键。使用类比、事例和简单的表述来让理解代码变得容易,让只有基础编程知识的人也能明白。尽量避免使用专业术语,如果必须使用,也要解释清楚。目标就是让读者能高屋建瓴地理解代码的运作和作用。

 

User:

import random

def bubble_sort(arr):
    n = len(arr)
    for i in range(n-1):
        for j in range(n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr

numbers = [random.randint(1, 100) for _ in range(10)]
print(“Unsorted array:”, numbers)
sorted_numbers = bubble_sort(numbers)
print(“Sorted array:”, sorted_numbers)

© 版权声明

相关文章