Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K
    資源
    概覽詞彙表系統提示詞
    提示詞庫Cosmic KeystrokesCorporate clairvoyantWebsite wizardExcel formula expertGoogle apps scripterPython bug busterTime travel consultantStorytelling sidekick引用您的來源SQL sorcererDream interpreterPun-ditCulinary creatorPortmanteau poetHal the humorous helperLaTeX legendMood colorizerGit gudSimile savantEthical dilemma navigatorMeeting scribeIdiom illuminatorCode consultantFunction fabricatorNeologism creatorCSV converterEmoji encoderProse polisherPerspectives pondererTrivia generatorMindfulness mentorSecond-grade simplifierVR fitness innovatorPII purifierMemo maestroCareer coachGrading guruTongue twisterInterview question crafterGrammar genieRiddle me thisCode clarifierAlien anthropologistData organizerBrand builderEfficiency estimatorReview classifierDirection decoderMotivational museEmail extractorMaster moderatorLesson plannerSocratic sageAlliteration alchemistFuturistic fashion advisorPolyglot superpowersProduct naming proPhilosophical musingsSpreadsheet sorcererSci-fi scenario simulatorAdaptive editorBabel's broadcastsTweet tone detectorAirport code analyst
    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
    提示詞庫

    函數製造器

    根據詳細規格創建 Python 函數。

    將此提示複製到我們的開發者 Console 中親自試用!

    內容
    System您的任務是根據提供的自然語言請求創建 Python 函數。請求將描述函數所需的功能,包括輸入參數和預期返回值。請根據給定的規格實現函數,確保它們處理邊緣情況、執行必要的驗證,並遵循 Python 程式設計的最佳實踐。請在程式碼中包含適當的註釋來解釋邏輯並協助其他開發者理解實現。
    User我想要一個可以解決數獨謎題的函數。該函數應該接受一個 9x9 的數獨網格作為輸入,其中空格用值 0 表示。該函數應該使用回溯演算法解決謎題並返回已解決的網格。如果謎題無法解決,它應該返回 None。該函數還應該驗證輸入網格以確保它是一個有效的數獨謎題。

    範例輸出

    Python
    def solve_sudoku(grid):
       def is_valid(row, col, num):
           # 檢查數字在當前行和列中是否有效
           for i in range(9):
               if grid[row][i] == num or grid[i][col] == num:
                   return False
    
           # 檢查數字在當前 3x3 子網格中是否有效
           start_row, start_col = (row // 3) * 3, (col // 3) * 3
           for i in range(3):
               for j in range(3):
                   if grid[start_row + i][start_col + j] == num:
                       return False
    
           return True
    
       def backtrack(row, col):
           # 如果我們已經填滿所有格子,謎題就解決了
           if row == 9:
               return True
    
           # 如果我們已經到達當前行的末尾,移動到下一行
           if col == 9:
               return backtrack(row + 1, 0)
    
           # 如果當前格子已經填滿,移動到下一個格子
           if grid[row][col] != 0:
               return backtrack(row, col + 1)
    
           # 嘗試用 1 到 9 的數字填充當前格子
           for num in range(1, 10):
               if is_valid(row, col, num):
                   grid[row][col] = num
                   if backtrack(row, col + 1):
                       return True
                   grid[row][col] = 0
    
           # 如果找不到有效數字,回溯
           return False
    
       # 驗證輸入網格
       if not all(len(row) == 9 and all(0 <= cell <= 9 for cell in row) for row in grid):
           return None
    
       # 開始回溯演算法
       if backtrack(0, 0):
           return grid
       else:
           return None
    

    API 請求

    • API 請求