Get startedGet started for free

Analyze solution correctness

You're back from your relaxing vacation and you've been assigned the task of reviewing and correcting some programming tasks, including a function to calculate of the area of a shape. You are provided with a code string that contains the function to calculate the area of a rectangle, and need to assess its correctness. The ideal function for you is a function that has correct syntax, receives two inputs, and returns one output.

The OpenAI package and the get_response() function have been pre-loaded for you.

This exercise is part of the course

ChatGPT Prompt Engineering for Developers

View Course

Exercise instructions

  • Create a multi-step prompt asking the model to assess the function provided in the delimited code string according to the three criteria: correct syntax, receiving two inputs, and returning one output.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

client = OpenAI(api_key="")

code = '''
def calculate_rectangle_area(length, width):
    area = length * width
    return area
'''

# Create a prompt that analyzes correctness of the code
prompt = ____

response = get_response(prompt)
print(response)
Edit and Run Code