Learn Before
Examples of Prompts for Python Code Generation
Prompts for code generation instruct a Large Language Model (LLM) to create code using natural language. These prompts can range in complexity. For instance, a user might request, 'Please write a Python function to calculate the average of a list of numbers,' or more simply, 'Write a Python program to calculate the sum of squares of the following numbers.' Both are effective commands for generating specific, functional code.
0
1
Tags
Ch.3 Prompting - Foundations of Large Language Models
Foundations of Large Language Models
Computing Sciences
Ch.2 Generative Models - Foundations of Large Language Models
Foundations of Large Language Models Course
Related
Example of a Prompt for Sequence Completion
Examples of Prompts for Python Code Generation
A developer has started writing a Python function but needs help finishing the implementation. They have the following code:
def calculate_factorial(n): """Calculates the factorial of a non-negative integer n.""" # Implementation needed hereThey want to use a language model to generate the rest of the function's code. Which of the following prompts is most likely to yield a correct, efficient, and contextually appropriate code completion?
Critiquing an AI-Generated Code Snippet
A developer provides a language model with the following Python code and comment, asking it to complete the function:
def find_even_numbers(num_list): # return a new list containing only the even numbers from num_listBelow are four different outputs the model could generate. Match each output to the most accurate description of its quality or potential issue.
Learn After
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