{"id":22230,"date":"2021-09-23T19:09:34","date_gmt":"2021-09-23T13:39:34","guid":{"rendered":"https:\/\/python-programs.com\/?p=22230"},"modified":"2021-11-22T18:35:41","modified_gmt":"2021-11-22T13:05:41","slug":"python-program-to-print-series-6-11-21-36-56-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-series-6-11-21-36-56-n\/","title":{"rendered":"Python Program to Print Series 6, 11, 21, 36, 56…n"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Print Series 1, 2, 4, 8, 16, 32…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 (6,11,21,36,56…N) <\/strong>for\u00a0the 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 1, 2, 4, 8, 16, 32…n Given a number N and the task is to print the series (6,11,21,36,56…N) for\u00a0the given number N in Python. Examples: Example1: Input: Given Number = 6 Output: The above series till the given number{ 6 } is …<\/p>\n
\nGiven a number N and the task is to print the series (6,11,21,36,56…N) <\/strong>for\u00a0the given number N in Python.<\/p>\nGiven Number = 6<\/pre>\n
The above series till the given number{ 6 } is :\r\n6 11 21 36 56 81<\/pre>\n
Given Number = 10<\/pre>\n
The above series till the given number{ 10 } is :\r\n6 11 21 36 56 81 111 146 186 231<\/pre>\n
Program to Print Series 6,11,21,36,56…n in Python<\/h2>\n
\n
Method #1: Using While Loop (Static Input)<\/h3>\n
\n
# Give the number N as static input and store it in a variable.\r\ngvn_numb = 6\r\n# Take a variable to say itr and initialize its value to 1.\r\nitr = 1\r\n# Take another variable to say previos_val and initialize its value to 6.\r\nprevios_val = 6\r\n# Take the other variable to say gvn_diffence and initialize its value to 5\r\n# (which is the common difference).\r\ngvn_diffence = 5\r\nprint(\"The above series till the given number{\", gvn_numb, \"} is :\")\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 while loop, print the value of the above previos_val value\r\n # separated by spaces.\r\n print(previos_val, end=\" \")\r\n # Add the given difference to the previous value and store it in the same\r\n # variable previos_val.\r\n previos_val = previos_val + gvn_diffence\r\n # Add 5 to the given difference and\u00a0store it in the same variable.\r\n gvn_diffence = gvn_diffence + 5\r\n # Increment the value of the above itr value by 1 and store it in the\r\n # same variable.\r\n itr += 1\r\n<\/pre>\n
The above series till the given number{ 6 } is :\r\n6 11 21 36 56 81<\/pre>\n
Method #2: Using While loop (User Input)<\/h3>\n
\n
# Give the number N 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 1.\r\nitr = 1\r\n# Take another variable to say previos_val and initialize its value to 6.\r\nprevios_val = 6\r\n# Take the other variable to say gvn_diffence and initialize its value to 5\r\n# (which is the common difference).\r\ngvn_diffence = 5\r\nprint(\"The above series till the given number{\", gvn_numb, \"} is :\")\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 while loop, print the value of the above previos_val value\r\n # separated by spaces.\r\n print(previos_val, end=\" \")\r\n # Add the given difference to the previous value and store it in the same\r\n # variable previos_val.\r\n previos_val = previos_val + gvn_diffence\r\n # Add 5 to the given difference and\u00a0store it in the same variable.\r\n gvn_diffence = gvn_diffence + 5\r\n # Increment the value of the above itr value by 1 and store it in the\r\n # same variable.\r\n itr += 1\r\n<\/pre>\n
Enter some Random Number = 10\r\nThe above series till the given number{ 10 } is :\r\n6 11 21 36 56 81 111 146 186 231<\/pre>\n
\n