Biblioteca de Prompts
Fabricante de funciones
Recursos
- Overview
- Inicios rápidos
- Ficha técnica de Claude 3
- Tarjeta de sistema de Claude 3.7
- Estado del sistema
- Cursos de Anthropic
- Biblioteca de Prompts
- Biblioteca de Prompts
- Pulsaciones Cósmicas
- Clarividente corporativo
- Asistente de sitios web
- Experto en fórmulas de Excel
- Programador de scripts para Google Apps
- Corrector de errores de Python
- Consultor de viajes en el tiempo
- Compañero de narración
- Cita tus fuentes
- Hechicero SQL
- Intérprete de sueños
- Pun-dit
- Creador culinario
- Poeta de palabras combinadas
- Hal el ayudante humorístico
- Leyenda de LaTeX
- Colorizador de estados de ánimo
- Git gud
- Genio de los símiles
- Navegador de dilemas éticos
- Escriba de reuniones
- Iluminador de modismos
- Consultor de código
- Fabricante de funciones
- Creador de neologismos
- Conversor de CSV
- Codificador de emojis
- Pulidor de prosa
- Evaluador de perspectivas
- Generador de trivias
- Mentor de atención plena
- Simplificador de segundo grado
- Innovador de fitness en RV
- Purificador de PII
- Maestro de memorandos
- Entrenador de carrera profesional
- Gurú de calificación
- Trabalenguas
- Creador de preguntas para entrevistas
- Genio gramatical
- Adivina adivinanza
- Clarificador de código
- Antropólogo alienígena
- Organizador de datos
- Creador de marca
- Estimador de eficiencia
- Clasificador de reseñas
- Decodificador de instrucciones
- Musa motivacional
- Extractor de correos electrónicos
- Moderador experto
- Planificador de lecciones
- Sabio socrático
- Alquimista de aliteraciones
- Asesor de moda futurista
- Superpoderes políglotas
- Experto en nombres de productos
- Reflexiones filosóficas
- Hechicero de hojas de cálculo
- Simulador de escenarios de ciencia ficción
- Editor adaptativo
- Transmisiones de Babel
- Detector de tono de tweets
- Analista de códigos de aeropuerto
Biblioteca de Prompts
Fabricante de funciones
Crea funciones de Python basadas en especificaciones detalladas.
Copia este prompt en nuestra Consola para desarrolladores para probarlo tú mismo.
Contenido | |
---|---|
System | Tu tarea es crear funciones de Python basadas en las solicitudes en lenguaje natural proporcionadas. Las solicitudes describirán la funcionalidad deseada de la función, incluyendo los parámetros de entrada y el valor de retorno esperado. Implementa las funciones de acuerdo con las especificaciones dadas, asegurándote de que manejen casos extremos, realicen las validaciones necesarias y sigan las mejores prácticas para la programación en Python. Por favor, incluye comentarios apropiados en el código para explicar la lógica y ayudar a otros desarrolladores a entender la implementación. |
User | Quiero una función que pueda resolver un rompecabezas de Sudoku. La función debe tomar como entrada una cuadrícula de Sudoku de 9x9, donde las celdas vacías están representadas por el valor 0. La función debe resolver el rompecabezas utilizando un algoritmo de backtracking y devolver la cuadrícula resuelta. Si el rompecabezas no tiene solución, debe devolver None. La función también debe validar la cuadrícula de entrada para asegurarse de que es un rompecabezas de Sudoku válido. |
Ejemplo de salida
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
Solicitud 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