python倒三角代碼 在python中用while語句打印出倒三角形?
在python中用while語句打印出倒三角形?#打印倒等邊三角形hang=int(input(“please input lines:”)y=1,y=0:Print(“*”,end=”)x-=1pr
在python中用while語句打印出倒三角形?
#打印倒等邊三角形hang=int(input(“please input lines:”)y=1,y=0:Print(“*”,end=”)x-=1print()y=1print(“graphic Printing completed!“)
代碼示例:
hang=int(輸入(”請輸入行數(shù):“)
Xing=hang*2-1
Kong=0
表示范圍內(nèi)的I(hang,0,-1):
Xing=I*2-1
Kong=hang-I
print(“*Kong”*“*Xing) character(string)*number表示字符串中可以放置多少次空格
1
2
3
4
5
6
7
上面的代碼指定要打印的行數(shù):
如果輸入5,您可以得到:
請輸入行數(shù):5
!**
*
python打印倒立的等腰三角形?
代碼示例:
loop method
STR1=[1,2,3,4
]STR2=[
對于STR1中的I:
STR2。Insert(0,I)
print(STR2)
slicing method
temporary
alist=[1,2,3
]print(alist[:::-1])輸出為:[3,2,1]