In this example, we will learn us how to create a Fibonacci sequence with Python.
The Fibonacci sequence is defined as F (X) +F (X+1) =F (X+2).
#! /usr/bin/env python3 # -*- coding: utf-8 -*- a = int(input("please input the first num in the sequence: ")) def FB(n): if n==1 or n==2: return int(a) return FB(n-1)+FB(n-2) print('Last number in Fibonacci Sequence:') print(FB(10))
please input the first num in the sequence: 12 Last number in Fibonacci Sequence: 660