我正在努力提高自己在python中的技能,但是我对课程材料的一部分深感困惑。我们面临的挑战是创建一个程序,该程序要求用户提供“钻石”大小的一半并打印附件图像,即两颗钻石,它们之间有一个空格。我能够得到一颗钻石,但无法弄清楚如何打印两颗钻石,有人可以帮忙吗,附上我的代码。
def Diamond(rows):
n = 0
for i in range(1, rows + 1):
# loop to print spaces
for j in range (1, (rows - i) + 1):
print(end = " ")
# loop to print star
while n != (2 * i - 1):
print("*", end = "")
n = n + 1
n = 0
# line break
print()
k = 1
n = 1
for i in range(1, rows):
# loop to print spaces
for j in range (1, k + 1):
print(end = " ")
k = k + 1
# loop to print star
while n <= (2 * (rows - i) - 1):
print("*", end = "")
n = n + 1
n = 1
#line break
print()
# number of rows input
rows = int(input("Please enter the size of half of a diamond: "))
Diamond(rows)