Program to Print Series 0, 6, 10, 17, 22, 30, 36...N

Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N

In the previous article, we have discussed Python Program to Print Series 10, 5, 60, 15, 110 …N
Given a number N and the task is to print the series (0, 6, 10, 17, 22, 30, 36…N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 16

Output:

The above series till the given number{ 16 } is :
0 6 10 17 22 30 36 45 52 62 70 81 90 102 112 125

Example2:

Input:

Given Number (Limit) = 11

Output:

The above series till the given number{ 11 } is :
0 6 10 17 22 30 36 45 52 62 70

Program to Print Series 0, 6, 10, 17, 22, 30, 36…N in Python

Below are the ways to print the series (0, 6, 10, 17, 22, 30, 36…N) till the given number N in Python:

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say m and initialize its value to 0.
  • Take another variable say n and initialize its value to 6.
  • Take another variable say x and initialize its value to 10.
  • Take another variable say y and initialize its value to 11.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of n separated by spaces.
  • Add the above y value to n and store it in the same variable n.
  • Increment the above y value by 2.
  • Else,  print the value of m separated by spaces.
  • Add the above x value to m and store it in the same variable m.
  • Increment the above x value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 16
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say m and initialize its value to 0.
m = 0
# Take another variable say n and initialize its value to 6.
n = 6
# Take another variable say x and initialize its value to 10.
x = 10
# Take another variable say y and initialize its value to 11.
y = 11
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
        # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if (itr % 2 == 0):
        # If it is true, then print the value of n separated by spaces.
        print(n, end=" ")
        # Add the above y value to n and store it in the same variable n.
        n += y
        # Increment the above y value by 2.
        y += 2
    else:
        # Else, print the value of m separated by spaces.
        print(m, end=" ")
        # Add the above x value to m and store it in the same variable m.
        m += x
        # Increment the above x value by 2.
        x += 2
   # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 16 } is :
0 6 10 17 22 30 36 45 52 62 70 81 90 102 112 125

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say m and initialize its value to 0.
  • Take another variable say n and initialize its value to 6.
  • Take another variable say x and initialize its value to 10.
  • Take another variable say y and initialize its value to 11.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of n separated by spaces.
  • Add the above y value to n and store it in the same variable n.
  • Increment the above y value by 2.
  • Else,  print the value of m separated by spaces.
  • Add the above x value to m and store it in the same variable m.
  • Increment the above x value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say m and initialize its value to 0.
m = 0
# Take another variable say n and initialize its value to 6.
n = 6
# Take another variable say x and initialize its value to 10.
x = 10
# Take another variable say y and initialize its value to 11.
y = 11
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
        # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if (itr % 2 == 0):
        # If it is true, then print the value of n separated by spaces.
        print(n, end=" ")
        # Add the above y value to n and store it in the same variable n.
        n += y
        # Increment the above y value by 2.
        y += 2
    else:
        # Else, print the value of m separated by spaces.
        print(m, end=" ")
        # Add the above x value to m and store it in the same variable m.
        m += x
        # Increment the above x value by 2.
        x += 2
   # Increment the above itr value by 1.
    itr += 1

Output:

Enter some Random Number = 11
The above series till the given number{ 11 } is :
0 6 10 17 22 30 36 45 52 62 70