-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" Fibonacci sequence | ||
Generates a list consisting of fibonacci numbers from F(0) | ||
to F(n) for the input n | ||
Arguments: | ||
n -- The nth fibonacci number to generate to. | ||
simulation -- whether or not the script should return info | ||
about an estimation of phi | ||
""" | ||
def fibonacci(n, simulation=False): | ||
f_nums = [1,1] | ||
for x in range(1,n): | ||
f_nums.append(f_nums[x-1] + f_nums[x]) | ||
if (simulation): | ||
phi = (1 + 5**0.5)/2 | ||
print(f_nums) | ||
print("F({}) - F({}) = {}".format(n, n-1, f_nums[-1]/f_nums[-2])) | ||
print("The true value of phi is {}".format(phi)) | ||
return f_nums |