Skip to content

Instantly share code, notes, and snippets.

@MohanSha
Created February 13, 2018 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohanSha/e800eded2a3b14cc699de026228d07bc to your computer and use it in GitHub Desktop.
Save MohanSha/e800eded2a3b14cc699de026228d07bc to your computer and use it in GitHub Desktop.
Generate a Fibonacci Sequence
# Fibonacci Sequence
# Enter a number and have the program generate the Fibonacci sequence to
# that number or to the Nth number.
def get_fibonacci_seq(n):
res = [1,1]
while len(res) < n:
res.append(res[-1] + res[-2])
return res[:n]
if __name__ == "__main__":
try:
n = int(raw_input("How many numbers in the sequence? "))
seq = get_fibonacci_seq(n)
print seq
except:
print "Invalid input"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment