Learn Before
Example of a Prompt and Completion for a Python Average Function
When instructing a language model trained on language and code to perform a code completion task, a prompt such as 'Please write a Python function to calculate the average of a list of numbers.' can be used. The model completes the prompt by generating the corresponding code block, such as a calculate_average function that gracefully handles both populated and empty lists by returning the sum divided by the length, or 0 if empty.
0
1
Tags
Foundations of Large Language Models
Ch.3 Prompting - Foundations of Large Language Models
Foundations of Large Language Models Course
Computing Sciences
Related
A developer needs a Python function to calculate the average of a list of numbers. A crucial requirement is that the function must return 0 if the input list is empty, instead of raising an error. The developer provides the following natural language instruction to a code-generating tool: 'Write a Python function to calculate the average of a list of numbers.' Which of the following statements best evaluates this instruction's quality for the intended purpose?
Refining a Prompt for Python Code Generation
Crafting a Python Code Generation Prompt
Example of a Prompt and Completion for a Python Average Function