From f253d7f293fc709c6a8409721199b2bf7279057d Mon Sep 17 00:00:00 2001 From: Hinal-Srivastava Date: Thu, 1 Oct 2020 09:04:46 +0530 Subject: [PATCH] User defined Fibonacci Series in Python --- Code/Factorial_of_nth_Number.py | 14 ++++++++++++++ Code/factorial.py | 29 +++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 Code/Factorial_of_nth_Number.py diff --git a/Code/Factorial_of_nth_Number.py b/Code/Factorial_of_nth_Number.py new file mode 100644 index 0000000..21dacd7 --- /dev/null +++ b/Code/Factorial_of_nth_Number.py @@ -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)) \ No newline at end of file diff --git a/Code/factorial.py b/Code/factorial.py index f0f7ef0..856f4f6 100644 --- a/Code/factorial.py +++ b/Code/factorial.py @@ -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) - \ No newline at end of file +# 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)) \ No newline at end of file