Skip to content

Fibonacci Series in Python #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit 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
14 changes: 14 additions & 0 deletions Code/Factorial_of_nth_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributed by @Hinal-Srivastava
def Fibonacci(n):
if n<0:
print("Incorrect input")
elif n==1:
return 0
elif n==2:
return 1
else:
return Fibonacci(n-1)+Fibonacci(n-2)

# Driver Program
n = int(input("Enter Number: "))
print(Fibonacci(n))
29 changes: 13 additions & 16 deletions Code/factorial.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

#program to find the factorial of a number provided by a user

if __name__ == "__main__":
number = int(raw_input("Enter a number to get its factorial: "))
factorial = 1

if number < 0:
print("Sorry, factorial doesn't exist for negative numbers!")
elif number == 0:
print("The factorial of 0 is 1")
else:
for i in range(1, number + 1):
factorial = factorial * i
print "The factorial of %r is %r" % (number, factorial)

# Contributed by @Hinal-Srivastava
def Fibonacci(n):
if n<0:
print("Incorrect input")
elif n==1:
return 0
elif n==2:
return 1
else:
return Fibonacci(n-1)+Fibonacci(n-2)

# Driver Program
print(Fibonacci(100))