:construction: :construction: :construction: :cons...
# ask-marvin
n
🚧 🚧 🚧 🚧 🚧 🚧 Marvin is going to sleep for a bit, will update when back 🚧 🚧 🚧 🚧 🚧 🚧
@Marvin hey write a task that computes fibonacci to n, no commentary. name task run w the input
m
Sure! Could you please specify if you are using Prefect 2.x or Prefect 3.x? This will help me provide you with the correct code snippet.
n
@Marvin 3.x
m
Here's how you can define a task in Prefect 3.x to compute the Fibonacci sequence up to
n
and name the task run with the input:
Copy code
python
from prefect import flow, task

@task(task_run_name=lambda n: f"fibonacci-{n}")
def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

@flow
def fibonacci_flow(n):
    result = fibonacci(n)
    print(f"Fibonacci of {n} is {result}")

# Example usage
fibonacci_flow(10)
This code defines a task that computes the Fibonacci number for a given
n
, and the task run is named dynamically based on the input value of
n
. For more information, you can check Prefect's flow and task documentation.
🙌 1