+ 2

How to make there be others between the lines of characters using loops (I don't know how to write the question correctly)

Code: for i in range(5): print ('x' * 8) Output: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx I need: xxxxxxxx xxxxxxxx xxzzzzxx xxxxxxxx xxxxxxxx

9th Dec 2022, 7:06 AM
Dmitry Frolov
Dmitry Frolov - avatar
3 Answers
+ 1
for i in range(5): line = "" for j in range(8): if i == 2 and j > 1 and j < 6: line += "z" else: line += "x" print(line)
9th Dec 2022, 8:09 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 2
for i in range(5): If i == 2: print(f'{2*"x"}{{4*"z"}{2*"x"}') Else: print("x"*8)
9th Dec 2022, 9:24 AM
Oma Falk
Oma Falk - avatar