for x in [0, 1, 1, 3]:
for y in [0, 2, 1, 2]:
print(‘*’)
You may want to paste your code in a
code block
which preserves
indentation
Just use the </>
button to create the block.
Not clear what your question is: the code, if I understand how it was supposed to be indented, doesn’t really do anything interesting. It just prints 16 *
characters, one per line.
it’s an indentation error in line2, line3 , the output of this coad is 16*
Your code is using nested iteration that must be written as below:
for x in [0, 1, 1, 3]:
for y in [0, 2, 1, 2]:
print('*')
So, * will take as for each x element 4 y elements. In elaboration it’s like:
for x=0 >
y=0
print('*') Next>
y=2
print('*') Next>
y=1
print('*') Next>
y=2
print('*') Next>
for x=1 >
y=0
print('*') Next>
So on … till x=3 & y=2
Hence, * will be printed 16 times.
Hope, this helps!
Thanks.