Loading...
    • 개발자 가이드
    • API 레퍼런스
    • MCP
    • 리소스
    • 릴리스 노트
    Search...
    ⌘K
    리소스
    개요용어집시스템 프롬프트
    프롬프트 라이브러리Cosmic Keystrokes기업 예측가웹사이트 마법사Excel 수식 전문가Google Apps 스크립터Python 버그 버스터시간 여행 컨설턴트스토리텔링 도우미출처 인용하기SQL 마법사꿈 해석가말장난 전문가요리 크리에이터합성어 시인유머러스한 도우미 HalLaTeX 달인감정 색채화Git 달인직유법 달인윤리적 딜레마 탐색기회의록 작성기관용구 해설가코드 컨설턴트함수 생성기신조어 생성기CSV 변환기이모지 인코더문장 다듬기관점 탐구가퀴즈 생성기마음챙김 멘토초등학생 수준 쉽게 설명하기VR 피트니스 혁신가개인정보 정제기메모 달인커리어 코치채점 전문가잰말놀이면접 질문 제작기문법 요정수수께끼 풀기코드 해설기외계인 인류학자데이터 정리기브랜드 빌더효율성 추정기리뷰 분류기방향 해독기동기부여 뮤즈이메일 추출기마스터 모더레이터수업 계획기소크라테스식 현자두운법 연금술사미래형 패션 어드바이저다국어 초능력제품 네이밍 전문가철학적 사색스프레드시트 마법사SF 시나리오 시뮬레이터적응형 편집기바벨의 방송트윗 톤 감지기공항 코드 분석기
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    프롬프트 라이브러리

    코드 해설기

    복잡한 코드를 쉬운 언어로 단순화하고 설명합니다.

    이 프롬프트를 개발자 Console에 복사하여 직접 사용해 보세요!

    내용
    SystemYour 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.
    Userimport 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)

    예시 출력

    이 코드는 숫자 목록을 오름차순으로 정렬하는 데 사용되는 버블 정렬 알고리즘의 구현을 보여줍니다. 단계별로 살펴보겠습니다:

    1. 코드는 먼저 'random' 모듈을 가져오는 것으로 시작합니다. 이 모듈은 예시를 위한 난수를 생성하는 데 사용됩니다.

    2. 'bubble_sort' 함수가 정의되며, 이 함수는 숫자 배열(리스트)을 입력으로 받습니다. 이 함수가 정렬 작업을 수행합니다.

    3. 'bubble_sort' 함수 내부에서 변수 'n'에 입력 배열의 길이가 할당됩니다. 이는 정렬에 필요한 반복 횟수를 결정하는 데 사용됩니다.

    4. 변수 'i'로 제어되는 첫 번째 루프는 'n-1'번 반복합니다. 이는 'n-1'번의 패스 후에 가장 큰 숫자가 배열의 끝에 위치하게 되므로 다시 비교할 필요가 없기 때문입니다.

    5. 변수 'j'로 제어되는 두 번째 루프는 'n-i-1'번 반복합니다. 이는 각 패스 후에 정렬되지 않은 요소 중 가장 큰 숫자가 끝에 배치되므로 다음 패스에서 비교할 필요가 없기 때문입니다.

    6. 두 번째 루프 내부에는 배열의 인접한 요소를 비교하는 if 문이 있습니다. 인덱스 'j'의 요소가 인덱스 'j+1'의 요소보다 크면 서로 교환됩니다. 이를 통해 더 큰 요소가 배열의 끝 쪽으로 이동합니다.

    7. 교환은 Python 구문 'arr[j], arr[j+1] = arr[j+1], arr[j]'를 사용하여 수행되며, 이는 'arr[j+1]'의 값을 'arr[j]'에, 'arr[j]'의 값을 'arr[j+1]'에 동시에 할당합니다.

    8. 모든 반복이 완료되면 정렬된 배열이 'bubble_sort' 함수에 의해 반환됩니다.

    9. 예시 코드에서는 리스트 컴프리헨션 '[random.randint(1, 100) for _ in range(10)]'을 사용하여 1에서 100 사이의 난수 10개로 구성된 리스트가 생성됩니다. 밑줄 '_'은 인덱스 값이 필요하지 않으므로 자리 표시 변수로 사용됩니다.

    10. 정렬되지 않은 배열이 출력되어 숫자의 초기 순서를 보여줍니다.

    11. 'bubble_sort' 함수가 'numbers' 배열을 입력으로 호출되고, 정렬된 배열이 'sorted_numbers' 변수에 저장됩니다.

    12. 마지막으로, 정렬된 배열이 출력되어 숫자를 오름차순으로 표시합니다.

    더 쉽게 말하면, 순서가 뒤섞인 숫자 목록이 있다고 상상해 보세요. 버블 정렬 알고리즘은 각 숫자를 옆에 있는 숫자와 비교하고, 순서가 잘못되어 있으면 교환하는 방식으로 작동합니다. 이 과정은 전체 목록이 정렬될 때까지 여러 번 반복됩니다. 마치 거품이 수면으로 떠오르는 것처럼, 각 패스에서 더 큰 숫자가 점차 목록의 끝 쪽으로 이동합니다.


    API 요청

    import anthropic
    
    client = anthropic.Anthropic(
        # defaults to os.environ.get("ANTHROPIC_API_KEY")
        api_key="my_api_key",
    )
    message = client.messages.create(
        model="claude-opus-4-6",
        max_tokens=1000,
        temperature=0,
        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.",
        messages=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "import random\n\ndef bubble_sort(arr):\n    n = len(arr)\n    for i in range(n-1):\n        for j in range(n-i-1):\n            if arr[j] > arr[j+1]:\n                arr[j], arr[j+1] = arr[j+1], arr[j]\n    return arr\n\nnumbers = [random.randint(1, 100) for _ in range(10)]\nprint(\"Unsorted array:\", numbers)\nsorted_numbers = bubble_sort(numbers)\nprint(\"Sorted array:\", sorted_numbers)"
                    }
                ]
            }
        ]
    )
    print(message.content)
    

    Was this page helpful?

    • API 요청