我在打印替代图案时遇到问题,输出应该是这样的:
input height: 7
22
1122
221122
11221122
2211221122
112211221122
22112211221122
但结果却是这样的:
input height: 7
22
1111
222222
11111111
2222222222
111111111111
22222222222222
代码:
height = int (input ("input height: "))
for level in range (1, height+1):
num = level
for x in range (num):
if( level%2==0): #Even row starts with "11" first
print ("11",end = "")
else:
print ("22",end = "")
print()
通过使用循环,while,for 循环,没有列表。我怎样才能做到这一点?