Python 用*打印各种形状

等腰三角形:

line = int(input('请输入边长'))
row = 1 
while row <= line:
	left = line - row +1
	while left >0:
		print(' ',end ='')
		left -= 1
	star = 2*row - 1
	star = row
	while star > 0:
		print('*',end ='')
		print(' ',end ='')  
		star -= 1
	right = line - row +1
	while right >0:
		print(' ',end ='')  
		right -= 1
	print('')
	row += 1

平行四边形:

 line = int(input('输入数字'))
row = line
 l = 1
while l < line  :
	i = l
	while i - 1 > 0: 
		print(' ', end = '')
		i -= 1
	r = row
	while r > 0: 
		print('*', end = '')
		r -= 1
	print('')
	l += 1 

三角形:
例一:

line = int(input('请输入边长'))
while line> 0:
	i = line 
	while  i > 0:
		print('*'*i)
		i -= 1
	i == 0 
	break
	print('')

例二:

i= 1
line = int(input('请输入边长'))
while i <= line:
	print('*'*i)
	i += 1

例三:
情况1:

line = int(input('请输入边长'))
row = 0 
while row <= line:
	l = row
	while l > 0:
		print(' ',end = '')
		l -= 1
	star = line -row +1
	while star >0:
		print('*',end= '')
		star -= 1
	print('')
	row += 1

情况二:

line = int(input('请输入打印的行数:'))
for k in range(1,line + 1):
	for n in range(1,k):
		print(' ',end='')
	row = line - k + 1
	for m in range(1,row + 1):
		print('*',end='')
	print('')

菱形:

line = int(input('请输入奇数行:'))
lineUp = int( (line + 1 ) / 2 )
lineDown = line // 2
for i in range(1,lineUp+1):
	space = lineUp - i
	for s in range(1,space + 1):
		print(' ',end = '')
	star = 2 * i -1
	for t in range(1,star + 1):
		print('*',end = '')
	print('')
for i in range(1,lineDown + 1):
	for s1 in range(1,i+1):
		print(' ',end = '')
	star1 = 2 * (lineDown - i) + 1
	for t in range(1,star1 + 1):
		print('*',end = '')
	print('')

你可能感兴趣的:(Python 用*打印各种形状)