Using a for-loop we show how to print an "angle" shape with the letter x.
x
x
x
x
x
x
x
There are two parts to the shape, a downward left direction, then a downward right direction. Breaking down a job into smaller tasks is often the best problem-solving strategy, and here the two directions can be different tasks.
For the downward left direction, the repetition consists of printing n (some number) of spaces, then "x", so that each iteration decreases n.
1 2 | for n in [7,5,3,1]:
print n*' ' + 'x'
|
For the downward right direction, the same idea can work, but with each iteration increasing n.
1 2 | for n in [1,3,5,7]:
print n*' ' + 'x'
|
Putting these two loops into one program results in:
for n in [7,5,3,1]: |
print n*' ' + 'x' |
for n in [1,3,5,7]: |
print n*' ' + 'x' |
The code doesn't quite produce what we'd starting out to do. Can you find a way to fix it?