Skip to content

Commit 37d25d0

Browse files
Create lucas_function
1 parent c3d4b9e commit 37d25d0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

dynamic_programming/lucas_function

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#DEFINING THE FUNCTION
2+
def lucas_func(n):
3+
#PREDFINING THE VALUES
4+
a = 2
5+
b = 1
6+
7+
if n == 0:
8+
return a
9+
10+
# GENERATING THE NUMBER
11+
for i in range(2, n + 1):
12+
c = a + b
13+
a = b
14+
b = c
15+
16+
return b
17+
18+
# USER INPUT
19+
n = int(input("Enter the position n to find the nth Lucas Number: "))
20+
print(f"The {n}th Lucas Number is: {lucas_func(n)}")
21+
22+
"""
23+
24+
THE OUTPUT:-
25+
Enter the position n to find the nth Lucas Number: 6
26+
The 6th Lucas Number is: 18
27+
28+
"""

0 commit comments

Comments
 (0)