gpt-4-1106-preview· openai
Suzhen/CodeChat
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION
- User
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION user: hi, make a short python script to print fibo numbers
- Assistant
Sure, here's a simple Python script that prints the Fibonacci sequence up to a certain number of terms:
def fibo(n): a, b = 0, 1 for _ in range(n): print(a, end=' ') a, b = b, a + b print() # Newline after printing the sequence # Define the number of terms you want to print num_terms = 10 # Call the function to print Fibonacci numbers fibo(num_terms)This script defines a function
fibothat takes an argumentn, specifying the number of terms of the Fibonacci sequence to print. It then prints numbers starting with 0 and 1 and continues by summing the two preceding numbers. Thenum_termsvariable is set to10, but you can change it to print as many terms in the sequence as you desire.