Question: This is my code in Python: def gen_pattern(chars): a = '' #keeps track first half of line b = '' #keeps track of last half
This is my code in Python:
def gen_pattern(chars): a = '' #keeps track first half of line b = '' #keeps track of last half of line f = '' #keeps track of final patern l = '' #Used to create each line w = len(chars) #Store length of chars for i in chars[::-1]: t = [a, i, b] if i == chars[len(chars) - 1]: l = i else: l = '.'.join(t) a = l[:int(len(l) / 2) + 1] b = a[::-1] l = l.center((w * 2 + w + 1), '.') f += l + ' ' f = f.rstrip(' ') l = f.split(' ') for i in range((w - 2), -1, -1): f = f + ' ' + l[i].rstrip(' ') return f This is what it needs to do:
For this next exercise, you'll need to complete the function gen_pattern, which, when called with a string of length 1, will print an ASCII art pattern of concentric diamonds using those characters. The following are examples of patterns printed by the function (note the newline at the end of the last line!):
> gen_pattern('X') X > gen_pattern('XY') ..Y.. Y.X.Y ..Y.. Which is currently not happening and I need help fixing it, thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
