Skip to content

Commit ea485d1

Browse files
Merge pull request #35 from PrateekRanjanSingh/master
Add Fibonacci.py
2 parents bd786c5 + c22df48 commit ea485d1

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

Code/factorial.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
2-
#program to find the factorial of a number provided by a user
3-
4-
if __name__ == "__main__":
5-
number = int(raw_input("Enter a number to get its factorial: "))
6-
factorial = 1
7-
8-
if number < 0:
9-
print("Sorry, factorial doesn't exist for negative numbers!")
10-
elif number == 0:
11-
print("The factorial of 0 is 1")
12-
else:
13-
for i in range(1, number + 1):
14-
factorial = factorial * i
15-
print "The factorial of %r is %r" % (number, factorial)
1+
2+
#program to find the factorial of a number provided by a user
3+
4+
if __name__ == "__main__":
5+
number = int(raw_input("Enter a number to get its factorial: "))
6+
factorial = 1
7+
8+
if number < 0:
9+
print("Sorry, factorial doesn't exist for negative numbers!")
10+
elif number == 0:
11+
print("The factorial of 0 is 1")
12+
else:
13+
for i in range(1, number + 1):
14+
factorial = factorial * i
15+
print "The factorial of %r is %r" % (number, factorial)
1616

Code/fibonacci.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def fibonacci(n):
2+
if(n <= 1):
3+
return n
4+
else:
5+
return(fibonacci(n-1) + fibonacci(n-2))
6+
n = int(input("Enter number of terms:"))
7+
print("Fibonacci sequence:")
8+
for i in range(n):
9+
print(fibonacci(i))
10+

0 commit comments

Comments
 (0)