Python for loop with non desired results -


i supposed integer input command line , have loop outputting:

aa bbaa aabbaa bbaabbaa 

where number of lines of output given input.

this have tried:

height = int(input('input height: '))  row in range(1,height+1):     pattern in range(1,row+1):         if row % 2 != 0:             x in range(1, pattern+1, 2):                 print('aa', end = '')                 break             x in range(2, pattern+1, 2):                 print('bb', end = '')                 break         else:             x in range(1, pattern+1, 2):                 print('bb', end = '')                 break             x in range(2, pattern+1, 2):                 print('aa', end = '')                 break     print() 

which gives:

input height: 4 aa bbbbaa aaaabbaabb bbbbaabbaabbaa 

the original post close viable solution, except unconditional breaks. solution modified version of original:

height = int(input('input height: '))  row in range(1,height+1):     pattern in range(1,row+1):         if row % 2 != 0:             if pattern % 2 == 1:                 print('aa', end = '')             else:                 print('bb', end = '')         else:             if pattern % 2 == 1:                 print('bb', end = '')             else:                 print('aa', end = '')     print() 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -