# Programming

## Text files in C#

Text files is an important topic to master in programming. In this post, you will learn how to use text files in C#. Why do we need files in programming? A computer can store data in two ways: Random Access Memory (RAM) Computer Files An example of the use of RAM to store data is …

## Unit test example for text file reading in Java

Unit tests are a great tool to have in every programmer’s toolbox. In this post, I’ll show an example of how to write a unit test to make sure your code for reading from a text file works properly. Let’s say we have two classes already implemented: Laptop and Lenovo. The class Laptop handle the …

## Python program to calculate the reverse of an integer number without using strings

In this post, I’ll show a Python program to calculate the reverse of an integer number without using strings. One reason for not using strings is that we want to focus on the algorithm instead of getting a solution we don’t fully understand. The other one is that converting big numbers to strings is a …

## Python program to calculate the greatest common divisor using the Euclidean Algorithm

The Euclidean Algorithm to calculate the greatest common divisor (GCD) has many applications. We use it in programming class for two reasons: to practice loops and recursion, and to promote algorithmic thinking. In this post, I’ll give you a description of the algorithm, as well as a few different implementations for you to practice loops … ## Python program to find the prime factors of an integer number

There are many examples of problems that can help you practice with loops. One of them is to find the prime factors of an integer number. In this post, I’ll show you a python program that will calculate the prime factors of an integer. What are the prime factors of an integer number? The prime …

## Python program to print the factors of a number

Creating a python program to print the factors of a number is another good exercise to keep practicing loops in any programming language. If you divide a number by a second number and you get as remainder 0, then the second number is a factor of the first one. For instance, 2 is a factor …

## Palindrome in Python

Let’s examine how to determine whether a word or sentence is palindrome or not in python. Words and/or sentences are palindrome when you can read them from beginning to end and vice versa and have the same meaning. In the case of sentences, we don’t consider the spaces and punctuation. Some examples are: Civic Radar …

## Python program to calculate Fibonacci numbers

Learn the best way to calculate Fibonacci numbers with this python program, as well as the recursive implementation. There is an interesting application of Fibonacci numbers. Consider that there is an idealized rabbit population. Newborn rabbits start mating in one month. And at the end of the second month, they produce another pair of rabbits. …

## Python program to calculate the factorial of a number

A great example to practice both, loops and recursion, is to create a python program to calculate the factorial of a number. The factorial of a number is defined as follows: f(n) = n * f(n-1) f(0)=f(1)=1 So, let’s start with the loop version of the program. Python program to calculate the factorial of a …

## Python program to add two matrices

Another example of practicing nested loops is a python program to add two matrices. Here, I’ll show the code and explain how to implement such a program. A general approach to adding two matrices When you add two matrices, you must add the numbers in the same position of each matrix, and that gives you …