1.直角三角形:
i = 1
while i<=5:
j = 1
while j <= i:
print("*",end='')
j+=1
print('\n')
i += 1
2.等腰三角形:
n = 5
for i in range(1,n+1):
for j in range(1,n+i):
if j < (n-i+1):
print(' ',end='')
else:
print("*",end='')
print('')
3.等边三角形
n = 5
for i in range(1, n + 1):
for j in range(1, n - i+1):
print(' ', end='')
print('* '*i)
4.九九乘法表:
for i in range(1,10):
for j in range(1,i+1):
print('%d*%d=%d'% (i,j,i*j),end=' ')
print('')