Print Shape In Python
In Python, I'd like to print a diamond shape of asterisks *: with $ at the top half of the diamond (upper pyramid) where there isn't a *, and with & at the bottom half of the
Solution 1:
def shape(n):
for i in range(2*n+ 1):
if (i < n):
print "$" * (n - i) + "*" * 2 * i + "$" * (n - i)
elif i == n:
print "*" * 2 * n
elif i > n:
print "&" * (i - n) + "*" * 2 * (2* n - i) + "&" * (i - n)
Post a Comment for "Print Shape In Python"