Python pattern looping -


i'm having trouble on printing alternate pattern, output suppose this:

input height: 7  22 1122 221122 11221122 2211221122 112211221122 22112211221122 

but instead came out this:

input height: 7 22 1111 222222 11111111 2222222222 111111111111 22222222222222 

code:

height = int (input ("input height: "))  level in range (1, height+1):     num = level      x in range (num):         if( level%2==0): #even row starts "11" first             print ("11",end = "")         else:             print ("22",end = "")     print() 

by using looping, while, loop, no list. how can this?

for inside x loop, level never changes. need alternate based on x while choosing start based on level.

height = int (input ("input height: "))  level in range (1, height+1):     num = level      x in range (num):         if( (level+x)%2==0): #even row starts "11" first             print ("11",end = "")         else:             print ("22",end = "")     print() 

notice how add level , x before modding against 2.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -