python输出等腰数字三角形(python输出等腰三角形代码)

http://www.itjxue.com  2023-03-24 11:47  来源:未知  点击次数: 

Python用while循环写一个等腰三角形

temp?=?input("打印几行:")

n?=?int(temp)

space=list('?'*(2*n-2))

mid=n-1

for?i?in?range(n):

????line=space.copy()

????if?i?!=?n-1:????????

????????line[mid-i]='*'

????????line[mid+i]='*'

????else:

????????line[:]='*'*(2*n-1)

????print(''.join(line))

求python大佬用双重for循环打印一个倒等腰直角空心三角形,5行5列的如图,在线等急急急

按照你的要求编写的用双重for循环打印一个倒等腰直角空心三角形的Python程序如下

n=5

for i in range(n,0,-1):

for j in range(i):

if j==0 or i==n or j==i-1:

print("*",end='')

else:

print(" ",end='')

print()

源代码(注意源代码的缩进)

Python 打印各种三角形

rows = int(input('输入列数:'))

for i in range(1, rows):

print('*' * i)

for i in range(1, rows):

for j in range(i):

print("*", end="")

print("")

rows = int(input('输入列数:'))

for i in range(1, rows):

print(' * ' * i)

for i in range(1, rows):

for j in range(1, i + 1):

print(" * ", end="")

print("")

rows = int(input('输入列数:'))

for i in range(1, rows):

if i % 2 != 0:

str = ('*' * i)

print(str.center(9, ' '))

rows = int(input('输入列数:'))

for i in range(0, rows):

print(" * " * rows)

for i in range(0, rows):

for j in range(0, rows):

print(" * ", end="")

print(" ")

for x in range(10):

for i in range(x, 10):

print('*', end='')

print('')

print('同一行打印直角三角形')

for j in range(10):

for x in range(0, j):

print(' ', end='')

for n in range(j, 19 - j):

print(' ', end='')

for k in range(0, j):

print(' ', end='')

print('')

print('直角三角形拼装心形')

for j in range(8):

for x in range(0, j):

print(' ', end='')

for n in range(j, 19 - j):

print(' ', end='')

for k in range(0, j):

print(' ', end='')

print('')

for i in range(10):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 10):

print('*', end=' ')

print('')

print('打印倒立等腰三角形1')

for j in range(10):

for x in range(0, j):

print(end=' ')

for n in range(j, 15 - j):

print('*', end='')

print('打印倒立等腰三角形2')

for i in range(10):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 10):

print('*', end=' ')

print('')

print('同一行打印两个等腰三角形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

for n in range(0, 0):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for jj in range(10, 10):

print(end=' ')

for kk in range(10 - i, 10):

print(' ', end=' ')

print('')

print('等腰三角形拼装心形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

for n in range(0, 0):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for jj in range(10, 10):

print(end=' ')

for kk in range(10 - i, 10):

print(' ', end=' ')

print('')

for i in range(20):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 20):

print('*', end=' ')

print('')

print('打印正方形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for n in range(0, 0 + i):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

print('')

PYTHON 等腰三角形 如何做程序?

def?triangle(n):

????s=''

????for?i?in?range(1,2*n+1):

????????if?i=n:

????????????s=s+'X'*i+'\n'

????????else:

????????????s=s+'X'*((n-i)+n)+'\n'

????print?s

if?__name__=="__main__":

????n=int(raw_input("please?input?triangle?len:"))

????triangle(n)

python 2.6.6测试,结果如题目要求

python使用for循环打印一个正立实心等腰三角形?

1、示例代码

def printTri():

for i in range(1, 7):

for j in range(1, (7 - i)):

print(' ', end='')

for k in range(1, 2 * i):

print('*', end='')

print()

printTri()

2、实例结果

*

***

*****

*******

*********

***********

(责任编辑:IT教学网)

更多

推荐金山WPS文章