for i in range(1,8,2): if i<7: str1='*'*i print(f'{str1:^5}') else: str1 = '*' print(f'{str1:^5}') 结果 * *** ***** *
for i in range(1,5): for j in range(5): if i > j: print("*",end='') print(" ") 结果 * ** *** ****