Biblioteca de Prompts
Fabricante de funções
Recursos
- Overview
- Guias de início rápido
- Cartão do modelo Claude 3
- Cartão do sistema Claude 3.7
- Status do sistema
- Cursos da Anthropic
- Biblioteca de Prompts
- Biblioteca de Prompts
- Teclas Cósmicas
- Clarividente corporativo
- Assistente de sites
- Especialista em fórmulas do Excel
- Programador de scripts do Google Apps
- Caçador de bugs em Python
- Consultor de viagem no tempo
- Parceiro de narrativas
- Cite suas fontes
- Feiticeiro SQL
- Intérprete de sonhos
- Trocadilhista
- Criador culinário
- Poeta de portmanteaus
- Hal, o ajudante bem-humorado
- Legenda LaTeX
- Coloridor de humor
- Git gud
- Mestre das comparações
- Navegador de dilemas éticos
- Meeting scribe
- Iluminador de expressões idiomáticas
- Consultor de código
- Fabricante de funções
- Criador de neologismos
- Conversor de CSV
- Codificador de emoji
- Polidor de prosa
- Ponderador de perspectivas
- Gerador de curiosidades
- Mentor de mindfulness
- Simplificador para segundo ano
- Inovador de fitness em RV
- Purificador de PII
- Mestre de memorandos
- Coach de carreira
- Guru de avaliação
- Trava-línguas
- Criador de perguntas para entrevistas
- Gênio da gramática
- Me decifre
- Esclarecedor de código
- Antropólogo alienígena
- Organizador de dados
- Construtor de marca
- Estimador de eficiência
- Classificador de avaliações
- Decodificador de direções
- Musa motivacional
- Extrator de email
- Moderador mestre
- Planejador de aulas
- Sábio socrático
- Alquimista de aliterações
- Consultor de moda futurista
- Superpoderes poliglotas
- Especialista em nomes de produtos
- Reflexões filosóficas
- Mago de planilhas
- Simulador de cenários de ficção científica
- Editor adaptativo
- Transmissões de Babel
- Detector de tom de tweets
- Analista de códigos de aeroporto
Biblioteca de Prompts
Fabricante de funções
Crie funções Python com base em especificações detalhadas.
Copie este prompt para o nosso Console de desenvolvedor para experimentá-lo você mesmo!
Conteúdo | |
---|---|
System | Sua tarefa é criar funções Python com base nas solicitações em linguagem natural fornecidas. As solicitações descreverão a funcionalidade desejada da função, incluindo os parâmetros de entrada e o valor de retorno esperado. Implemente as funções de acordo com as especificações fornecidas, garantindo que elas lidem com casos extremos, realizem as validações necessárias e sigam as melhores práticas de programação Python. Por favor, inclua comentários apropriados no código para explicar a lógica e auxiliar outros desenvolvedores a entender a implementação. |
User | Quero uma função que possa resolver um quebra-cabeça Sudoku. A função deve receber como entrada uma grade Sudoku 9x9, onde células vazias são representadas pelo valor 0. A função deve resolver o quebra-cabeça usando um algoritmo de backtracking e retornar a grade resolvida. Se o quebra-cabeça não tiver solução, deve retornar None. A função também deve validar a grade de entrada para garantir que seja um quebra-cabeça Sudoku válido. |
Exemplo de Saída
Python
def solve_sudoku(grid):
def is_valid(row, col, num):
# Check if the number is valid in the current row and column
for i in range(9):
if grid[row][i] == num or grid[i][col] == num:
return False
# Check if the number is valid in the current 3x3 subgrid
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 we have filled all cells, the puzzle is solved
if row == 9:
return True
# Move to the next row if we have reached the end of the current row
if col == 9:
return backtrack(row + 1, 0)
# If the current cell is already filled, move to the next cell
if grid[row][col] != 0:
return backtrack(row, col + 1)
# Try filling the current cell with numbers from 1 to 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
# If no valid number is found, backtrack
return False
# Validate the input grid
if not all(len(row) == 9 and all(0 <= cell <= 9 for cell in row) for row in grid):
return None
# Start the backtracking algorithm
if backtrack(0, 0):
return grid
else:
return None
Requisição de 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-20250514",
max_tokens=1000,
temperature=0,
system="Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle.",
}
],
}
],
)
print(message.content)
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-20250514",
max_tokens=1000,
temperature=0,
system="Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle.",
}
],
}
],
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: "my_api_key", // defaults to process.env["ANTHROPIC_API_KEY"]
});
const msg = await anthropic.messages.create({
model: "claude-opus-4-20250514",
max_tokens: 1000,
temperature: 0,
system: "Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle."
}
]
}
]
});
console.log(msg);
from anthropic import AnthropicBedrock
# See https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
# for authentication options
client = AnthropicBedrock()
message = client.messages.create(
model="anthropic.claude-opus-4-20250514-v1:0",
max_tokens=1000,
temperature=0,
system="Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle."
}
]
}
]
)
print(message.content)
import AnthropicBedrock from "@anthropic-ai/bedrock-sdk";
// See https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
// for authentication options
const client = new AnthropicBedrock();
const msg = await client.messages.create({
model: "anthropic.claude-opus-4-20250514-v1:0",
max_tokens: 1000,
temperature: 0,
system: "Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle."
}
]
}
]
});
console.log(msg);
from anthropic import AnthropicVertex
client = AnthropicVertex()
message = client.messages.create(
model="claude-3-7-sonnet-v1@20250219",
max_tokens=1000,
temperature=0,
system="Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle."
}
]
}
]
)
print(message.content)
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
// Reads from the `CLOUD_ML_REGION` & `ANTHROPIC_VERTEX_PROJECT_ID` environment variables.
// Additionally goes through the standard `google-auth-library` flow.
const client = new AnthropicVertex();
const msg = await client.messages.create({
model: "claude-3-7-sonnet-v1@20250219",
max_tokens: 1000,
temperature: 0,
system: "Your task is to create Python functions based on the provided natural language requests. The requests will describe the desired functionality of the function, including the input parameters and expected return value. Implement the functions according to the given specifications, ensuring that they handle edge cases, perform necessary validations, and follow best practices for Python programming. Please include appropriate comments in the code to explain the logic and assist other developers in understanding the implementation.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "I want a function that can solve a Sudoku puzzle. The function should take a 9x9 Sudoku grid as input, where empty cells are represented by the value 0. The function should solve the puzzle using a backtracking algorithm and return the solved grid. If the puzzle is unsolvable, it should return None. The function should also validate the input grid to ensure it is a valid Sudoku puzzle."
}
]
}
]
});
console.log(msg);
Was this page helpful?
On this page