Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)
OpenAssistant Conversations (oasst2)
Please write me python code to get all Fibonacci numbers until 10 with a recursive…
In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
- User
Please write me python code to get all Fibonacci numbers until 10 with a recursive function.
- Assistant
def _fibonacci_req(tm2=0, tm1=0, max_num=0): """ Function to recursively yield all Fibonacci numbers until max_num :param tm2: number at t-2 :param tm1: number at t-1 :param max_num: maximum number to yield :return: the fibonacci number at t """ if tm1 > max_num: return yield tm1 t = tm1+tm2 if tm1 > 0 else 1 yield from _fibonacci_req(tm1, t, max_num) def fibonacci_numbers(max_num=10): """ Function to get all Fibonacci numbers until max_num (default 10) :param max_num: maximum number of the list :return: """ return [x for x in _fibonacci_req(max_num=max_num)] - User
Thanks. Can you now update it to 15?
- Assistant
There's no need to update anything in the code.
If you want to use the number 15, all you have to do is pass that number into the
fibonacci_numbersfunction when you call it.Here's an example:
# Call the fibonacci function and pass the number 15 sequence = fibonacci_numbers(15) # Print each number in the sequence for n in sequence: print(n)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →