Answer:
What's wrong?
The line_str variable needs to be re-initialized at the end of each printing
The correction
Include the following line immediately after the print statement
line_str = ""
Explanation:
Required
Correct the code
The conditions are correct. However, the string variable line_str needs to be set to an empty string at the end of every of the iteration loop.
This will allow the code to generate a new string.
So, the complete function is:
<em>def swapping_stars():
</em>
<em> line_str = ""
</em>
<em> for line in range(0, 6):
</em>
<em> for char in range(0,6):
</em>
<em> if line % 2 == char%2:
</em>
<em> line_str += "*"
</em>
<em> else:
</em>
<em> line_str += "-"
</em>
<em> print(line_str)
</em>
<em> line_str = ""</em>