From 37d25d005d49a0482a76a6c1e11433b0de2dba9a Mon Sep 17 00:00:00 2001 From: DEVANSH GAJJAR <162860692+DEVANSH-GAJJAR@users.noreply.github.com> Date: Wed, 18 Jun 2025 18:57:15 +0530 Subject: [PATCH 1/2] Create lucas_function --- dynamic_programming/lucas_function | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dynamic_programming/lucas_function diff --git a/dynamic_programming/lucas_function b/dynamic_programming/lucas_function new file mode 100644 index 000000000000..15e33e26fb6f --- /dev/null +++ b/dynamic_programming/lucas_function @@ -0,0 +1,28 @@ +#DEFINING THE FUNCTION +def lucas_func(n): + #PREDFINING THE VALUES + a = 2 + b = 1 + + if n == 0: + return a + + # GENERATING THE NUMBER + for i in range(2, n + 1): + c = a + b + a = b + b = c + + return b + +# USER INPUT +n = int(input("Enter the position n to find the nth Lucas Number: ")) +print(f"The {n}th Lucas Number is: {lucas_func(n)}") + +""" + +THE OUTPUT:- +Enter the position n to find the nth Lucas Number: 6 +The 6th Lucas Number is: 18 + +""" From 0af04d75e77d5c49a89e9a970a3318edac472e78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:28:04 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dynamic_programming/lucas_function | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dynamic_programming/lucas_function b/dynamic_programming/lucas_function index 15e33e26fb6f..419007b4e7bb 100644 --- a/dynamic_programming/lucas_function +++ b/dynamic_programming/lucas_function @@ -3,25 +3,25 @@ def lucas_func(n): #PREDFINING THE VALUES a = 2 b = 1 - + if n == 0: return a - - # GENERATING THE NUMBER + + # GENERATING THE NUMBER for i in range(2, n + 1): c = a + b a = b b = c - + return b - -# USER INPUT + +# USER INPUT n = int(input("Enter the position n to find the nth Lucas Number: ")) print(f"The {n}th Lucas Number is: {lucas_func(n)}") """ -THE OUTPUT:- +THE OUTPUT:- Enter the position n to find the nth Lucas Number: 6 The 6th Lucas Number is: 18