Another great week of learning new concepts, logics, commands, etc. in Python.

Let's get right into it.


  1. Persistence is the key

There's something Noufal Ibrahim said during one of the classes last week that stuck with me. He said something like, some people might grasp a new concept in 5 days and some will take 5 months but after 5 yrs, both are the same. Moreover, as I was reading the book "Learn Python The Hard Way" by Zed A. Shaw, there's a note from the author of the book. He says "As you study this book and continue with programming, remember that anything worth doing is difficult at first." Whatever are the reasons for wanting to quit, continue doing it even if you want to stop it. If you don't understand something, it's ok to take a break from it, ask for help, etc. But always come back to it later because in the beginning you'll struggle but then one day you'll suddenly "get it" if you don't give up. This made me realize that just like everything else worth pursuing, persistence is the key in learning software development.


We were given lots of quizzes in class. Our job was to write functions in Python which would give us the desired outcome. Following is one of the quizzes.

  1. Loops/Nested Loops:

Write a function 'table2(5)', when called will give the following output.

Think it on paper first. We were advised to solve it on paper first. Here's the logic.

Once the logic was clear, it became relatively easier to write a loop and nested loop which would give us the above output line by line and column by column.

Here the breakdown of the function:

def tables2(n)

Here tables2(n) has one parameter. In this function, the parameter n does not have a default value and is required (mandatory) during a call.

for i in range(1,n+1)

When the program needs to repeated some block several times, loops come in handy. There are for and while loop operators in Python, in this exercise we have used for.

Function range(min_value, max_value) generates a sequence with numbers min_value, min_value + 1, ..., max_value - 1. The last number is not included.

There's a reduced form of range() - range(max_value), in which case min_value is implicitly set to zero.

In the above function for j in range(1,n+1) is a nested loop. The program will first execute the outer loop, executing its first iteration. This first iteration triggers the inner, nested loop, which then runs to completion.

print (f "{i * j}", end=" ")

f“formatted string literals,” f-strings are string literals that have an f at the beginning and curly braces containing expressions that will be replaced with their values.

The print() function in Python inserts a new line at the end, by default. In Python 3, end ='  ' appends space instead of newline.

That's all for this week. If you have any feedback, please let me know.

Thank you for reading.