{"id":22613,"date":"2021-09-27T08:34:01","date_gmt":"2021-09-27T03:04:01","guid":{"rendered":"https:\/\/python-programs.com\/?p=22613"},"modified":"2021-11-22T18:35:39","modified_gmt":"2021-11-22T13:05:39","slug":"python-program-to-print-series-1-2-5-8-15-28-51-94-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-series-1-2-5-8-15-28-51-94-n\/","title":{"rendered":"Python Program to Print Series 1 2 5 8 15 28 51 94….N"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N<\/a> Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print the series (1 2 5 8 15 28 51 94….N)<\/strong> till the given number N in Python:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n If you wanna write simple python programs as a part of your coding practice refer to numerous Simple Python Program Examples<\/a> existing and learn the approach used.<\/p>\n In the previous article, we have discussed Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N Given a number N and the task is to print the series (1 2 5 8 15 28 51 94….N) till the given number N in Python. Examples: Example1: Input: Given Number (Limit) = 13 Output: …<\/p>\n
\nGiven a number N and the task is to print the series (1 2 5 8 15 28 51 94….N)<\/strong> till the given number N in Python.<\/p>\nGiven Number (Limit) = 13<\/pre>\n
The above series till the given number{ 13 } is :\r\n1 2 5 8 15 28 51 94 173 318 585 1076 1979<\/pre>\n
Given Number (Limit) = 8<\/pre>\n
The above series till the given number{ 8 } is :\r\n1 2 5 8 15 28 51 94<\/pre>\n
Program to Print Series 1 2 5 8 15 28 51 94….N in Python<\/h2>\n
\n
Method #1: Using While Loop (Static Input)<\/h3>\n
\n
# Give the number N(limit) as static input and store it in a variable.\r\ngvn_numb = 13\r\n# Take a variable to say itr and initialize its value to 4.\r\nitr = 4\r\nprint(\"The above series till the given number{\", gvn_numb, \"} is :\")\r\n# Check if the given number is greater than or equal to 1 using the if conditional\r\n# statement.\r\nif gvn_numb >= 1:\r\n # If it is true, then print 1 separated by spaces using the end function.\r\n print(\"1 \", end=\"\")\r\n# Check if the given number is greater than or equal to 2 using the if conditional\r\n# statement.\r\nif gvn_numb >= 2:\r\n # If it is true, then print 2 separated by spaces using the end function.\r\n print(\"2 \", end=\"\")\r\n# Check if the given number is greater than or equal to 3 using the if conditional\r\n# statement.\r\nif gvn_numb >= 3:\r\n # If it is true, then print 5 separated by spaces using the end function.\r\n print(\"5 \", end=\"\")\r\n# Take another variable say m and initialize its value to 1.\r\nm = 1\r\n# Take another variable say n and initialize its value to 2.\r\nn = 2\r\n# Take another variable say o and initialize its value to 5.\r\no = 5\r\n# Loop until the above-declared variable itr value is less than or equal to the\r\n# given number using the while loop.\r\nwhile itr <= gvn_numb:\r\n # Inside the loop, add the above 3 values m, n, o and store them in a variable\r\n # say rslt.\r\n rslt = m + n + o\r\n # Assign the value of n to m.\r\n m = n\r\n # Assign the value of o to n.\r\n n = o\r\n # Assign the value of rslt to o.\r\n o = rslt\r\n # Print the value of the\u00a0rslt separated by spaces using the end function.\r\n print(rslt, end=\" \")\r\n # Increment the above itr value by 1.\r\n itr += 1\r\n<\/pre>\n
The above series till the given number{ 13 } is :\r\n1 2 5 8 15 28 51 94 173 318 585 1076 1979<\/pre>\n
Method #2: Using While loop (User Input)<\/h3>\n
\n
# Give the number N (Limit) as user input using the int(input()) function and \r\n# store it in a variable.\r\ngvn_numb = int(input(\"Enter some Random Number = \"))\r\n# Take a variable to say itr and initialize its value to 4.\r\nitr = 4\r\nprint(\"The above series till the given number{\", gvn_numb, \"} is :\")\r\n# Check if the given number is greater than or equal to 1 using the if conditional\r\n# statement.\r\nif gvn_numb >= 1:\r\n # If it is true, then print 1 separated by spaces using the end function.\r\n print(\"1 \", end=\"\")\r\n# Check if the given number is greater than or equal to 2 using the if conditional\r\n# statement.\r\nif gvn_numb >= 2:\r\n # If it is true, then print 2 separated by spaces using the end function.\r\n print(\"2 \", end=\"\")\r\n# Check if the given number is greater than or equal to 3 using the if conditional\r\n# statement.\r\nif gvn_numb >= 3:\r\n # If it is true, then print 5 separated by spaces using the end function.\r\n print(\"5 \", end=\"\")\r\n# Take another variable say m and initialize its value to 1.\r\nm = 1\r\n# Take another variable say n and initialize its value to 2.\r\nn = 2\r\n# Take another variable say o and initialize its value to 5.\r\no = 5\r\n# Loop until the above-declared variable itr value is less than or equal to the\r\n# given number using the while loop.\r\nwhile itr <= gvn_numb:\r\n # Inside the loop, add the above 3 values m, n, o and store them in a variable\r\n # say rslt.\r\n rslt = m + n + o\r\n # Assign the value of n to m.\r\n m = n\r\n # Assign the value of o to n.\r\n n = o\r\n # Assign the value of rslt to o.\r\n o = rslt\r\n # Print the value of the\u00a0rslt separated by spaces using the end function.\r\n print(rslt, end=\" \")\r\n # Increment the above itr value by 1.\r\n itr += 1\r\n\r\n\r\n<\/pre>\n
Enter some Random Number = 8\r\nThe above series till the given number{ 8 } is :\r\n1 2 5 8 15 28 51 94<\/pre>\n
\n