Created
March 26, 2018 10:19
-
-
Save Hwatwasthat/b2c1d557ee8fbbefbc7588b113acd998 to your computer and use it in GitHub Desktop.
Fibonacci created by Hwatwasthat - https://repl.it/@Hwatwasthat/Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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