ComenzarEmpieza gratis

Writing Code Through Prompts: Compound Interest

You're setting aside a fixed amount of money each month into a savings account that earns interest.

Rather than calculating compound interest manually or in a spreadsheet, you decide to use an agent to write the code for you and answer your queries.

Note: For all exercises in this course, a model variable has already been initialized for you. It provides access to an OpenAI model behind the scenes. No setup or API keys required.

Este ejercicio forma parte del curso

AI Agents with Hugging Face smolagents

Ver curso

Instrucciones del ejercicio

  • Import the CodeAgent class from the smolagents library.
  • Create an instance of CodeAgent, passing it an empty list for tools.
  • Call the .run() method on your agent and pass in your task string.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Import the CodeAgent class
from smolagents import ____

# Create a basic agent without tools
agent = CodeAgent(tools=____, model=model)

task = "I deposit $100 every month into an account that pays 5% annual interest, compounded monthly. Calculate the total balance after 10 years."

# Run the agent
result = agent.____(task)
print(result)
Editar y ejecutar código