{"id":22562,"date":"2021-09-27T09:19:11","date_gmt":"2021-09-27T03:49:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=22562"},"modified":"2021-11-22T18:35:38","modified_gmt":"2021-11-22T13:05:38","slug":"python-program-to-print-series-6-9-14-21-30-41-54-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-series-6-9-14-21-30-41-54-n\/","title":{"rendered":"Python Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Print Series 1, -2, 6, -15, 31 … 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, 9, 14, 21, 30, 41, 54 … 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 Enhance your coding skills with our list of Python Basic Programs<\/a> provided and become a pro in the general-purpose programming language Python in no time.<\/p>\n In the previous article, we have discussed Python Program to Print Series 1, -2, 6, -15, 31 … N Given a number N and the task is to print the series (6, 9, 14, 21, 30, 41, 54 … N) till the given number N in Python. Examples: Example1: Input: Given Number (Limit) = 7 …<\/p>\n
\nGiven a number N and the task is to print the series (6, 9, 14, 21, 30, 41, 54 … N)<\/strong> till the given number N in Python.<\/p>\nGiven Number (Limit) = 7<\/pre>\n
The above series till the given number{ 7 } is :\r\n6 9 14 21 30 41 54<\/pre>\n
Given Number (Limit) = 10<\/pre>\n
The above series till the given number{ 10 } is :\r\n6 9 14 21 30 41 54 69 86 105<\/pre>\n
Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N\u00a0in 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 = 7\r\n# Take a variable to say itr and initialize its value to 1.\r\nitr = 1\r\n# Take another variable say k and initialize its value to 3.\r\nk = 3\r\n# Take another variable say valu and initialize its value to 6.\r\nvalu = 6\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 given\r\n# number using the while loop.\r\nwhile(itr <= gvn_numb):\r\n # Inside the loop,\u00a0print the value of the above variable valu separated by spaces.\r\n print(valu, end=\" \")\r\n # Add k value to the above\u00a0valu and store it in the same variable valu.\r\n valu += k\r\n # Increment the above k value by 2.\r\n k += 2\r\n # Increment the above itr value by 1.\r\n itr += 1\r\n<\/pre>\n
The above series till the given number{ 7 } is :\r\n6 9 14 21 30 41 54<\/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 1.\r\nitr = 1\r\n# Take another variable say k and initialize its value to 3.\r\nk = 3\r\n# Take another variable say valu and initialize its value to 6.\r\nvalu = 6\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 given\r\n# number using the while loop.\r\nwhile(itr <= gvn_numb):\r\n # Inside the loop,\u00a0print the value of the above variable valu separated by spaces.\r\n print(valu, end=\" \")\r\n # Add k value to the above\u00a0valu and store it in the same variable valu.\r\n valu += k\r\n # Increment the above k value by 2.\r\n k += 2\r\n # Increment the above itr value by 1.\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 9 14 21 30 41 54 69 86 105<\/pre>\n
\n