按照题目要求编写的打印菱形的Python程序如下
def diamond(n):
for i in range(1,2*n):
for j in range(1,abs(n-i)+1):
print (' ',end='')
for j in range(1,2*n-2*abs(n-i)):
print ('*', end='')
print()
while True:
n=int(input("请输入菱形的行数(输入0结束):"))
if n==0:
break
elif n>0:
diamond(n)
else:
continue
源代码(注意源代码的缩进)