Libreria di prompt
Cacciatore di bug Python
Risorse
- Overview
- Guide rapide
- Scheda modello Claude 3
- Scheda di sistema Claude 3.7
- Stato del sistema
- Corsi Anthropic
- Libreria di prompt
- Libreria di Prompt
- Battute Cosmiche
- Chiaroveggente aziendale
- Creatore di siti web
- Esperto di formule Excel
- Programmatore di script per Google apps
- Cacciatore di bug Python
- Consulente di viaggi nel tempo
- Compagno di narrazione
- Cita le tue fonti
- Stregone SQL
- Interprete dei sogni
- Pun-dit
- Creatore culinario
- Poeta di portmanteau
- Hal l'assistente umoristico
- Leggenda LaTeX
- Coloratore di stati d'animo
- Git gud
- Esperto di similitudini
- Navigatore di dilemmi etici
- Meeting scribe
- Illuminatore di modi di dire
- Consulente di codice
- Fabbricatore di funzioni
- Creatore di neologismi
- Convertitore CSV
- Codificatore di emoji
- Perfezionatore di prosa
- Valutatore di prospettive
- Generatore di quiz
- Mentore di mindfulness
- Semplificatore per la seconda elementare
- Innovatore di fitness VR
- Purificatore di PII
- Maestro dei memo
- Coach di carriera
- Guru della valutazione
- Scioglilingua
- Creatore di domande per colloqui
- Genio della grammatica
- Indovinello per te
- Chiarificatore di codice
- Antropologo alieno
- Organizzatore di dati
- Creatore di brand
- Stimatore di efficienza
- Classificatore di recensioni
- Decodificatore di direzioni
- Musa motivazionale
- Estrattore di email
- Moderatore esperto
- Pianificatore di lezioni
- Saggio socratico
- Alchimista dell'allitterazione
- Consulente di moda futuristica
- Superpoteri poliglotti
- Esperto di nomi di prodotti
- Riflessioni filosofiche
- Mago dei fogli di calcolo
- Simulatore di scenari di fantascienza
- Editor adattivo
- Trasmissioni di Babele
- Rilevatore del tono dei tweet
- Analista di codici aeroportuali
Libreria di prompt
Cacciatore di bug Python
Rileva e correggi bug nel codice Python.
Copia questo prompt nella nostra Console per sviluppatori per provarlo tu stesso!
Contenuto | |
---|---|
System | Il tuo compito è analizzare lo snippet di codice Python fornito, identificare eventuali bug o errori presenti e fornire una versione corretta del codice che risolva questi problemi. Spiega i problemi che hai trovato nel codice originale e come le tue correzioni li risolvono. Il codice corretto dovrebbe essere funzionale, efficiente e aderire alle migliori pratiche nella programmazione Python. |
User | def calculate_average(nums): sum = 0 for num in nums: sum += num average = sum / len(nums) return average numbers = [10, 20, 30, 40, 50] result = calculate_average(numbers) print(“The average is:”, results) |
Output di esempio
Codice Python corretto:
Python
def calculate_average(nums):
total = 0
for num in nums:
total += num
average = total / len(nums)
return average
numbers = [10, 20, 30, 40, 50]
result = calculate_average(numbers)
print("The average is:", result)
Spiegazione:
- Cambiato il nome della variabile “sum” in “total” per evitare di usare la funzione integrata di Python “sum()”.
- Corretto il refuso nell’istruzione print, cambiando “results” in “result” per fare riferimento correttamente alla variabile.
Richiesta 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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
)
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
)
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
});
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
)
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
});
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
)
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 analyze the provided Python code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in Python programming.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def calculate_average(nums):\n sum = 0\n for num in nums:\n sum += num\n average = sum / len(nums)\n return average\n\nnumbers = [10, 20, 30, 40, 50]\nresult = calculate_average(numbers)\nprint(\"The average is:\", results)"
}
]
}
]
});
console.log(msg);
Was this page helpful?
On this page