gpt-4-1106-preview· OpenAI
WildChat-4.8M (AI2)
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION
- User
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION user: make a python script to print fibonacci
- Assistant
Certainly! The Fibonacci sequence is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. Below is a simple Python script that prints the Fibonacci sequence up to a certain number of terms:
def fibonacci(n_terms): # First two terms n1, n2 = 0, 1 count = 0 # check if the number of terms is valid if n_terms <= 0: print("Please enter a positive integer.") elif n_terms == 1: print("Fibonacci sequence up to", n_terms, ":") print(n1) else: print("Fibonacci sequence:") while count < n_terms: print(n1) nth = n1 + n2 # update values n1 = n2 n2 = nth count += 1 # Your input goes here - the number of terms you want to see in the sequence num_terms = 10 fibonacci(num_terms)When you run this script, you'll see the first 10 terms of the Fibonacci sequence printed to your console. You can change the value of
num_termsto get more or fewer terms.