From 83828c468194c36d24b2880318e72c1b8c1f90aa Mon Sep 17 00:00:00 2001 From: DEVANSH GAJJAR <162860692+DEVANSH-GAJJAR@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:45:30 +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..789d42eb66f4 --- /dev/null +++ b/dynamic_programming/Lucas_function @@ -0,0 +1,28 @@ +#Giving the output +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 ce9b0ce3e8711ef62b8c17bb759aae6a6feafba0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Jun 2025 14:16:14 +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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dynamic_programming/Lucas_function b/dynamic_programming/Lucas_function index 789d42eb66f4..458668d0cc15 100644 --- a/dynamic_programming/Lucas_function +++ b/dynamic_programming/Lucas_function @@ -1,27 +1,27 @@ -#Giving the output +#Giving the output 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