Skip to content

Instantly share code, notes, and snippets.

@Hwatwasthat
Created March 26, 2018 10:19
Show Gist options
  • Save Hwatwasthat/b2c1d557ee8fbbefbc7588b113acd998 to your computer and use it in GitHub Desktop.
Save Hwatwasthat/b2c1d557ee8fbbefbc7588b113acd998 to your computer and use it in GitHub Desktop.
Fibonacci created by Hwatwasthat - https://repl.it/@Hwatwasthat/Fibonacci
import random
# function to generate required fibonacci sequence
def fibonacci(k):
# intiate counter
i = 1
# intiate list to iterate on
main_list = [0, 1]
# while loop to operate on list for duration k
while i < k:
# add next number to end of list by addition of previous two numbers in list
main_list.append(main_list[i] + main_list[i-1])
i += 1
# remove holding 0 from list
main_list.remove(0)
return main_list
ent = int(input("How many numbers in the sequence?"))
print (str(fibonacci(ent)).strip('[]'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment