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:

btnTryCodeOnline_Over

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:

btnTryCodeOnline_Over

This code would generate exacly 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

Share Button
Posted in Computer Science, Python - Beginner, Python Challenges Tagged with: , ,

Our Latest Book

Follow this blog