在Python中,你可以使用循环和条件语句来输出10行数据。以下是几种不同的方法:
方法一:使用循环和`end`参数
count = 0
for i in range(1, 11):
print(i, end=" ")
count += 1
if count % 10 == 0:
print()
方法二:使用`while`循环
num = 0
while num < 100:
print("*", end=" ")
num += 1
if (num + 1) % 10 == 0:
print()
方法三:使用函数打印杨辉三角形
def print_pascal_triangle(rows):
for i in range(rows):
print(" " * (rows - i - 1), end="")
C = 1
for j in range(0, i + 1):
print(C, end=" ")
C = C * (i - j) // (j + 1)
print()
print_pascal_triangle(10)