We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c3d4b9e commit 37d25d0Copy full SHA for 37d25d0
dynamic_programming/lucas_function
@@ -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