Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Fixed fibonacci.py and README #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Head to the issues page to see how you can contirbute to this repo.
If you've figuerd out how to fix things here then refer to ```CONTRIBUITNG.md``` to get started!

### Winners:
1.(Add Name Here)
1.Nitish
33 changes: 27 additions & 6 deletions py/fibonacci.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#function to fibonacci sequence
# Program to display the Fibonacci sequence up to n-th term where n is provided by the user

def fibonacci(n):
if n < 1:
return n
else:
return(fibonacci(n-1) + fibonacci(n-2))

nterms =int(input("Enter a Number :"))

# uncomment to take input from the user
#nterms = int(input("How many terms? "))

# first two terms
n1 = 0
n2 = 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence upto",nterms,":")
while count < nterms:
print(n1,end=' \n ')
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1