generate the nth fibonacci number in python

main.py
import math

def fib(n):
    phi = (1 + math.sqrt(5)) / 2
    return round(pow(phi, n) / math.sqrt(5))

# example usage
print(fib(6)) # prints 8
145 chars
9 lines

This is a simple implementation of the fibonacci sequence in Python. We use the formula phi^n / sqrt(5) to compute the nth fibonacci number, where phi is the golden ratio. The round function is used to round the result to the nearest integer. Note that this formula becomes inaccurate for large values of n due to floating point precision.

gistlibby LogSnag