Exercice 5 #7
DominiqueMakowski
started this conversation in
Show and tell
Replies: 6 comments 1 reply
-
def fibonacci(x):
n1, n2 = 0, 1
while n1 < x:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
fibonacci(10) |
Beta Was this translation helpful? Give feedback.
0 replies
-
def display_fibonacci(nterms):
if nterms > 0:
# nterms must be > 0
# first two terms
n1, n2 = 0, 1
for iterm in list(range(nterms)):
# Only print numbers up to nterms
print(f'Fibonacci number #{iterm + 1}: {n1}')
# update values
n1 = n2
n2 = n1 + n2
display_fibonacci(6) |
Beta Was this translation helpful? Give feedback.
0 replies
-
def fibonacci(x):
lst = [0,1]
for i in range(1, x):
element = lst[i-1] + lst[-1]
lst.append(element)
print(lst) |
Beta Was this translation helpful? Give feedback.
0 replies
-
def fibonacci(n):
"""itinitialize first and second fibonacci number"""
fib_first=1
fib_second=1
temp=''
"""iteraction from 1 until the last -1"""
for i in range(1,n-1):
temp = fib_first+fib_second
fib_first=fib_second
fib_second=temp
return fib_second
fibonacci(777) |
Beta Was this translation helpful? Give feedback.
0 replies
-
def fibonacci(r):
o = range(r)
n1 = 0
n2 = 1
for i in o:
x = n1 + n2
print(x)
n1 = n2
n2 = x
fibonacci(10) |
Beta Was this translation helpful? Give feedback.
1 reply
-
def Fibo (z):
n1 = 0
n2 = 1
for i in range(z):
print(n1)
num_fib = n1+n2
print(num_fib)
n1 = n1+num_fib
n2 = num_fib |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Create a function that takes a number as an input, and prints the Fibonacci sequence (0, 1, 1, 2, 3, 5, …) up until that number
Example:
Beta Was this translation helpful? Give feedback.
All reactions