In this article, you're going to learn on how to fix errors that come when you want to **write a program to print the first x terms of the series 3n+2 which are not multiples of 4**. Understanding the algorithm and pseudocode, is core toward solving the errors that arise.

**Reason for the Error**

The terms set for printing is derived from multiplying the equation 3n+2. The n in the formula can be any unique number unique from the initial.

In simple words, the program executes the equation 3n+2 with the changing variable n. With each change of n, the results of term is different. More importantly, the terms of the series that are printing should not be divisible by 4.

The main issues arise here. Majorly, the while loop is critical to enable recurrent program execution until certain condition is met. More so, the values should not be multiples of 4 hence the printed value modulus four should not equate to 0.

The x terms on the other hand is a variable set by the user and when the user sets such that the x terms are 5 then the program prints 5 terms in the 3n+2 series. All the terms should not be multiples of 4. In the next sections, and as stated, we take a look at the exact algorithm, pseudo code and program that accomplishes the task.

### **The Algorithm to print the first x terms of Series 3n+2 that are Not Multiples of 4**

The algorithm used for the program is especially simple:

**START**

**Step 1:** Take a variable lim.

**Step 2: **Assign the variable lim to an integer derived from user input.

**Step 3: **Create variable counter and assign to 0.

**Step 4:** Create a variable n and assign it to value 0.

**Step 5:** Perform while counter is not equal to 0

**Step 6:** If so, increment value n

**Step 7:** Create variable eq and assign to (3*n) +2

**Step 8:** If eq is greater than 4 and eq is not a multiple of 4 print eq

**Step 9:** Increment the counter

Now that we have the algorithm, let's have a look at the pseudo code.

**Pseudo code to Writer the first x Terms of the Series 3n+2 that are not Multiples of 4**

While counter is not equal to limit

Increment n term of the series

And execute the eq value

If the eq value is not a multiple of 4 and the eq is greater than 4

Print eq

Increment the counter

## **The Python Program that write first x Terms of a Series that are Not Multiples of 4**

We use the while counter to perform the operation. With while, the program checks if the value of counter is not equal to the eq value set by the user. If so, it first increment the present variable n by 1, and then uses n to execute the equation 3n+2. Here is the program that makes it happen:

```
while counter != lim:
```

```
n +=1
eq=(3*n)+2
```

The python programming language has got an operator called modulus that returns the remainder after a given division. As in our case, after executing the equation 3n+2, and checking whether the result is a multiple of 4, the result of modulus can either be a 0 or any other value. If the result is a 0 then then the value of eq is a multiple of 4 and hence not desired for our program. Otherwise, the output is correct and hence the print statement executes. Also, a program that is a multiple of 4 has to be greater than 4 and hence the program checks if that is accomplished too.

Now let us have a look to check whether the value is a multiple of 4 or not:

```
if (eq % 4 != 0) and (eq>4):
```

Moving ahead here is the complete code that implement the program:

```
lim=int(input())
counter=0
n=0
while counter != lim:
n +=1
eq=(3*n)+2
if (eq % 4 != 0) and (eq>4):
print(eq)
counter += 1
```

Executing the program at first prompts the user to enter the number of terms x in the series. In this case, let us enter the value 6. The output of the program is as follows:

5

11

14

17

23

26

**Conclusion.**

Now that you have gone through this post, you now understand how to w**rite a program to print the first x terms of the series 3n+2 which are not multiples of 4 **with deep details. Hopefully, this post adds value adds value in your quest toward building the program.