Python Patterns

Here is a quick challenge to focus on the use of loops, nested loops and string manipulation using Python.

Let’s look at the following code:

This code uses nested “for” loops (a loop within a loop). The output will be as follows:

PythonPattern-1

Note that there are sometimes more than one solution to the same problem. Look at the following code which makes more effective use of string concatenation techniques:

This code would generate exactly the same outcome. It is more effective as it performs the same task using less instructions and iterations.

You can now adapt these techniques to try to produce the following patterns…

Python Patterns

Did you like this challenge?

Click on a star to rate it!

Average rating 2.9 / 5. Vote count: 38

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , ,