ComenzarEmpieza gratis

Decoding functions with the right prompts

You’re on the Sales Data Analytics team at a city mobility rental company that offers bikes and motorbikes for short-term rentals. Pricing is dynamic: during peak hours (7–10 AM, 5–8 PM) no discounts apply; during off-peak hours, prices can drop by up to 40% based on demand and usage.

The function below computes prices and is saved in pricing.py, a file the LLM can read and use:

def calc_price(base_price, is_peak, discount_ratio):
  if is_peak:
    return base_price
  return base_price * (1 - 0.4 * discount_ratio)

Este ejercicio forma parte del curso

AI-Assisted Coding for Developers

Ver curso

Instrucciones del ejercicio

- Prompt the model to improve the function for better **readability and correctness**, including context about peak and off-peak pricing and the **dynamic pricing use case**, and asking to return the answer as **PEP 8–formatted Python code**.

Ejercicio interactivo práctico

Pon en práctica la teoría con uno de nuestros ejercicios interactivos

Empezar ejercicio