Categories
Python Programming

Branching

The default mode of execution of a program is from top to bottom. However in the course of the execution of a program, the Python interpreter comes across some statements that change the default mode of execution.

Such statements are called a branch. A branch is an instruction in a computer program that causes a computer to begin executing a different instruction sequence and thus deviate from its default behaviour of executing instructions in order.

Branching is implemented as a series of control statements in high level programming languages. In the Python programming language, these include:

  • IF Statement
  • WHILE Loop
  • FOR Loop

IF Statement

IF Statement
If-Then-Else flow diagram

The IF Statement works by evaluating a programmer specified boolean condition and checking if it evaluates to true or false.

If the condition evaluates to true, certain actions are carried out. An evaluation to false means that alternate actions are carried out.

WHILE Loop

While loop flow diagram

A loop ensures that code is repeated. However in programming when you want ensure that you loop an infinite number of times, you use a WHILE loop.

The WHILE loop consists of a block of code and a condition/expression. The condition/expression is evaluated, and if the condition/expression is true, the code within all of their following in the block is executed. This repeats until the condition/expression becomes false.

In the Python programming language, the WHILE loop has an ELSE branch just like the IF statement.

FOR Loop

For loop flow diagram

When you want to loop a fixed number of times in the Python programming language, you use a FOR loop.

A FOR loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. FOR loops are typically used when the number of iterations is known before entering the loop.

Conclusion

Branching statements allow the flow of execution to jump to a different part of the program.

Mastering them is important in the journey of learning how to program.

Categories
Uncategorized

Twitter Pulse Week 2

Welcome to a new week. The above graph shows the interest in the Canadian Permanent Residence among Nigerians. Take note of the regions where there are spikes in the graph.

The Goodbye Nigeria post led to Nigerians doing the #snowpose on Twitter. Nigerians from countries with winter took pictures of themselves in the snow.

Elegushi Beach

COVID-19 is in Lagos. Disregarding all warnings by the government, Lagosians stormed the beach on the first Sunday of the year. You can view the picture below:

Elegushi Beach

Such as situation is the ideal environment for the Coronavirus to be spread and some of the beach goers have now tested positive.

Elegushi Beach Aftermath

Panti After Party

The government with view to curbing the spread of the dreaded Coronavirus has placed an embargo on clubs, bars and restaurants.

Sadly, Lagosians didn’t heed the warnings and some of them were caught by the Lagos State Taskforce.

Party Goers
Panti After Party

FG to Borrow Dormant Account Balance

Dormant Accounts

As part of measures to shore up the national purse, the Federal Government has started borrowing from dormant accounts.

DNA Testing

After the FCMB Scandal, Twitter NG was buzzing with reasons why men should do DNA Testing.

Most heart-wrenching is the story below:

Family Feud I
Family Feud II
Family Feud III

Code of Conduct

How bad the level of poverty in Nigeria is can be felt by the code of conduct of a supermarket in Port-harcourt.

You can read this below:

Code of Conduct 1
Code of Conduct 2
Code of Conduct 3

As you can see for yourself, this isn’t a code of conduct, it is the terms of slavery.

Categories
Uncategorized

Twitter Pulse Week 1

Welcome to the new year. Since Twitter is where the pulse of the nation can be felt, I realise that it would be nice to curate tweets the resonate with me.

The above image is the story of the GDP of Nigeria from 2000 to 2019. You can tell for yourself how well the current administration has performed.

Goodbye Nigeria

Goodbye Nigeria

A Twitter user finally achieved his goal of leaving Nigeria. He came on Twitter to celebrate and met with serious backlash.

Backlash
Backlash Continues

If that was all, I would not feel bad. Sadly, more was to come:

Bad Belle

Sadly, one of the commentators lives in Canada.

Wizard

Clout Chasing

How far people will go for clout can be seen in the actions of a Twitter user called Didi of Malaysia. When called out, she had no reply.

Clout Chasing

Rape Attitude

False Rape Allegation

Today rape has become trivialised. The prevailing attitude about rape is simply scary.

Rape Mindset
Rape Setup

Feast Afrique

Feast Afrique has released a digital library of culinary text. One of the reminders that Twitter like real life comes with its own ray of hope.

Categories
Uncategorized

Welcome to a New Year

In the last weeks of 2020, the NIN issue which hounded JAMB registration in the early part of 2020 reared its ugly head.

Amidst the panic caused by the sudden announcement that everyone must link their SIM cards to their NIN, we have made it into a new year.

I once wrote the article My Top 10 Predictions for 2020 for the year 2020. Considering the fact that I missed the most important event of the year 2020, I won’t be making any prediction for the New Year.

However, I wish everyone reading this a prosperous 2021.

Categories
Python Programming

Euclid’s Algorithm I

Euclid’s Algorithm allows you to find the HCF of two numbers. The steps of the algorithm are given below:

  1. Ask the user for 2 numbers
  2. Test which one is bigger
  3. Make the bigger number m and the smaller number n
  4. Set r to be the remainder when m is divided by n
  5. Set n to m
  6. Set r to n
  7. If r is 0, the HCF is n. Stop
  8. Else go back to step 5

This article will cover steps 1 to 3. The first step is to create a script and name it euclid.py.

To write the code for step 1, enter the code shown below into the script:

# Ask the user for the first number
first_number = int(input("Please enter the first number: "))

# Ask the user for the second number
second_number = int(input("Please enter the second number: "))

To test which of the input numbers is bigger, we will use the greater than symbol. We will ignore other cases. The code to do this is shown below:

# Test if the second number is bigger than the first number
if (second_number > first_number):
    # Swap if the first number is greater than the second number
    temp = second_number
    second_number = first_number
    first_number = temp

# Print out to check the swap
print(first_number, second_number)

Now the program can receive input and swap them correctly. Below is an image of a running program.

Sample Program Run