-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.py
More file actions
57 lines (43 loc) · 914 Bytes
/
recursion.py
File metadata and controls
57 lines (43 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
""" RECURSIVE PROGRAMS """
# SUMMING THE ITEMS IN A LIST
# FACTORIAL NUMBER
import math
import turtle
def factorials(n):
if n <= 1:
print(" n! = ", 1)
else:
fact = 1
for x in range(1,n+1):
fact = fact * x
print(fact)
factorials(5)
# MATHS FACTORIALS
print(math.factorial(5))
myTurtle = turtle.Turtle()
myWin = turtle.Screen()
#FIBONNACI SEQUENCE
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
def fibonacci(n):
if n <= 0:
return n
else:
firstterm = 0
secterm = 1
counter = 0
seq= []
while counter < n:
next = firstterm + secterm
firstterm = secterm
secterm = next
counter+=1
seq.append(firstterm)
print(seq)
fibonacci(10)
def fibo(n):
if n < 0:
print("ONLY POSTIVE")
else:
n1 =0
n2 =1
return fibo()