LoslegenKostenlos loslegen

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)

Diese Übung ist Teil des Kurses

AI-Assisted Coding for Developers

Kurs anzeigen

Anleitung zur Übung

- 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**.

Interaktive Übung

In dieser interaktiven Übung kannst du die Theorie in die Praxis umsetzen.

Übung starten