Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guillermohernandez/737ec1b16080c1856594de1f60fef86d to your computer and use it in GitHub Desktop.
Save guillermohernandez/737ec1b16080c1856594de1f60fef86d to your computer and use it in GitHub Desktop.

Exercise Nº 1 Using a nested for loop, print the string "hello" 12 times. Use different combinations of numbers. For example, the outer loop would loop 6 times and the inner one 2 times (6*2 = 12). Etc.

Exercise Nº 2 Create a nested for loop to produce the following string:

*
**
***
****
*****

Then turn it into a function that accepts 2 parameters, the height and the width of the structure. Finally, extend it to take a third argument to invert the structure.

Exercise Nº 3 Create a nested for loop to produce the following string:

....1
...22
..333
.4444
55555

Try the above exercise using just 1 nested for loop, and also try making it work with 2 nested loops inside the outer loop (3 loops in total, something like):

for i in range(XXX):
    for j in range(YYY):
        pass
    for m in range(ZZZ):
        pass

Exercise Nº 4 Create a nested for loop to produce a matrix with a diagonal containing the number 1 and filled by *:

1****
*1***
**1**
***1*
****1

Turn it into a function that accepts the parameters: size (4x4, 8x8, etc), number to use in the diagonal and character to fill the rest. Modify it to accept a third parameter to invert the diagonal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment