Pseudocode illustrates the procedure in natural language on how to achieve a goal. Pseudocode is important because it will allow us to see an overview of all tasks, recognize step by step how tasks are executed and the intent of each task. It is not perfect as predicting the future is not that easy but it serves as a guide and gives direction in achieving the target.
In this article, our goal is to sum all the given numbers provided that each number is divisible by four. A number is divisible by four if the remainder is zero after dividing that number by four.
Mathematics is broad, by learning its different concepts, such as greatest common factor; multiplication; number divisibility; sum; multiples; factors; and others, it allows us to understand more of it which will prepare us to solve mathematical problems from our work and even in our day to day living.
The input numbers can be from a user whom we will prompt. First, we need to build a pseudocode, and second we will create a Python code based on the pseudocode.
The problem is to sum all the given numbers that are divisible by four. But we need to show the pseudocode and its equivalent python code. In the subsequent sections, we will discuss pseudocode, divisibility by four rules and remainder.
We will follow a scenario where the program takes the input number, checks if it is divisible by four and if so, adds the number to the total. Note that we only deal with whole numbers such as 5, 10, etc. but not float numbers such as 8.5, 12.5 and others with decimal points.
Pseudocode is a written instruction or procedure that uses human language in order to achieve an objective. Each line is a task that is actionable. These tasks are numbered where the first task has to be finished before the second and so on. A task may include a subtask to break down a complicated task.
Python has keywords such as if
, else
, while
, True
, False
, or
, continue
, and break
that are also used in the English language. We can use them to generate pseudocode.
- Pseudocode can be understood by everybody not only the programmers but also the non-programmers.
- People collaborate effectively in achieving the project goals.
- Issues that may arise are only minimal as pseudocode passes a thorough review.
- It is easier to resolve issues as everyone knows about the project's plan.
- Pseudocode can assist finance people in providing a good estimate of the costs and profits.
Pseudocode can be updated to reflect what is on the actual implementation. Future similar projects may benefit from this updated pseudocode.
Our goal is to multiply two numbers and print the product.
pseudocode
1. Asks the user to input the first number, remember it by storing the same into the variable x.
2. Asks the user to input the second number, remember it by storing the same into the variable y.
3. Multiply x and y to get the product.
4. Print the product.
filename: sample_multiply.py
code
x = int(input("Enter the first number? "))
y = int(input("Enter the second number? "))
product = x * y
print(product)
You can copy paste the code above and try to run it on your favorite IDE, I use visual studio code.
run result

We get two numbers, multiply them to get the product and print the result. Our pseudocode has 4 tasks while our code has 4 statements. Each statement in the code corresponds to each task in pseudocode. Statements in the code are executed in sequence from line 1 down to line 4.
Sum or total is the result when we add two or more numbers. If we add 1 and 1 the sum is 2. If we add 10, 20 and 30, the sum is 60.
total_1 = 1 + 1
total_2 = 10 + 20 + 30
A remainder is a number that is left after performing a division without applying decimal calculation. It is also a division process where the quotient or result is a whole number meaning the remainder is zero. Being able to calculate the remainder is crucial in determining if a number is divisible by four or not.
Here are some examples.
Our basic formula is:
quotient = dividend / divisor
Formula with remainder and without decimal point.
quotient = (dividend / divisor) + (remainder / divisor)
Here we will use the long division process.
a. Calculate the remainder if the dividend is 12 and the divisor is 4
(Explanation)
3
---
4)12
12 (3 x 4 = 12)
---
0 (12 - 12 = 0, stop here since 0 is less than 4) <-- remainder
The remainder is zero.
So 12 / 4 = 3 + 0/4 or 3 remainder 0.
b. Calculate the remainder if the dividend is 20 and the divisor is 8
(Explanation)
2
---
8)20
16 (2 x 8 = 16)
---
4 (20 - 16 = 4, stop here since 4 is less than 8) <-- remainder
So 20 / 8 = 2 + 4/8 or 2 remainder 4.
In this example the remainder is 4.
c. Calculate the remainder if the dividend is 5 and the divisor is 8
(Explanation)
0
---
8)5
0 (0 x 8 = 0)
---
5 (5 - 0 = 5, stop here since 5 is less than 8)
The remainder is 5.
Python has two easy ways to get the remainder.
- Use the modulo operator
%
- Use the divmod built-in function.
a. Use modulo operator %
Find the remainder if the first number is 874 and the second number is 4?
code
remainder = 874 % 4
print(f'The remainder is {remainder}.')
output
The remainder is 2.
b. Use divmod built-in function
The divmod()
takes two parameters. The first is the dividend and the second is the divisor. It returns a tuple of two numbers, the first is the quotient from integer division and the second number is the remainder.
divmod(a, b)
Given a=100 and b=3 find the quotient and the remainder.
filename: mydivmod.py
code
a = 100
b = 3
quotient, remainder = divmod(a, b)
print(f'a: {a}, b: {b}, quotient: {quotient}')
print(f'a: {a}, b: {b}, remainder: {remainder}')
run result

You may continue reading (part 2/2).