多组输入,一个整数(2~20)。
针对每行输入,输出用“*”组成的菱形,每个“*”后面有一个空格。
2
* * * * * * * * *
3
* * * * * * * * * * * * * * * *
4
* * * * * * * * * * * * * * * * * * * * * * * * *
while True: try: n = int(input()) for i in range(1,2*n+2): if i <= n+1: print(" "*(n+1-i)+"* "*i) else: print(" "*(i-(n+1))+"* "*((n+1)-(i-(n+1)))) except: break
import sys while True: try: num=int(sys.stdin.readline().strip()) numl=num+1 for i in range(numl): print(("* "*(i+1)).center(numl*2)) if i==num: for j in range(num,0,-1): print(("* "*j).center(numl*2)) except: break
while True: try: n = int(input()) for i in range(1, 2 * n + 2): if i in range(1, n + 1): print(" " * (n-i+1) + "* " * i + " " * (n-1)) elif i == n + 1: print("* " * (n + 1)) elif i in range(n + 2, 2 * n + 2): print(" " * (i-n-1) + "* " * (2*n+2-i) + " " * (n-1)) except: break