Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Numeric concentric squares pattern by @CodingComputing
- max_num = 4 # given parameter
- # Construct the central row
- inc_nums = list(range(1, max_num+1))
- centre_row = inc_nums[:0:-1] + inc_nums
- size = len(centre_row) # infer the size
- for num in centre_row:
- row = centre_row.copy() # Each row is derived from centre row
- # Replace a middle slice by repeated num
- slice_start = max_num - num
- slice_stop = size - slice_start
- row[slice_start:slice_stop] = [num]*(num*2-1)
- print(' '.join([str(item) for item in row])) # format and print
- # Follow @CodingComputing for more on Python!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement