这是我的代码,但我一直得到左三角形:
def RTriangle(n):
row = 1
while row <= n:
col = 1
while col <= row:
print("*", end="")
col = col + 1
print()
row = row - 1
def test_rt():
for i in range(5, 12, 3):
RTriangle(i)
print()
test_rt()
答案 0 :(得分:0)
在Python中,你实际上可以乘以一个字符串(这会将字符串复制x次),这意味着你不必逐个打印出来。例如,"cat" * 3
提供"catcatcat"
以下是解决方案:
def RTriangle(n):
col = 0
while col <= n:
print(" " * (n - col),"*" * col)
col = col + 1
def test_rt():
for i in range(5, 12, 3):
RTriangle(i)
print()
test_rt()