Lesson 6
Dealing with Sequences of Objects
Chapter 4: for loops
More patterns
Hope you enjoyed constructing the patterns in the previous exercise!
If you have a lot of time and want to practise more, I have more patterns for you to try below. Each solution usually requires only a small tweak to your previous solution.
These are entirely optional!!! Only do these if you are bored, have lots of time to spare, and want to practise your for
loops with range
objects! They can get addictive! Otherwise, please do move on to the next page!
Pattern #1
*
. *
. . *
. . . *
. . . . *
. . . . . *
. . . . . . *
. . . . . . . *
. . . . . . . . *
Pattern #2
. . . . . . . . *
. . . . . . . *
. . . . . . *
. . . . . *
. . . . *
. . . *
. . *
. *
*
Pattern #3
. . . . *
. . . *
. . *
. *
*
. *
. . *
. . . *
. . . . *
Pattern #4
This next one is a toughie! If you are stuck, step away from your code and think carefully!
. . . . *
. . . * * *
. . * * * * *
. * * * * * * *
* * * * * * * * *
. * * * * * * *
. . * * * * *
. . . * * *
. . . . *
If you are really stuck, here’s a tip: in each row, figure out the relationship between the number of dots and the number of stars. You might also want to involve the total number of columns (including the blanks), i.e. 9
.
Pattern #5
This is probably one of the easiest once you have solved the previous one!
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
Pattern #6
*
* . *
* . * . *
* . * . * . *
* . * . * . * . *
* . * . * . *
* . * . *
* . *
*
Hint 1: You are allowed to use building blocks other than loops!
Hint 2: even odd even odd
Hope you did not get too addicted. If that still did not satisfy you enough, this page has 30 patterns for you to try!