python while循环

python 打印九九乘法表
#九九乘法表,
#问题,无法对齐

# row=1 col=1
# row=2 col=2
# row=3 col=3
# 规律 列数和行数的关系,
row=1
while(row<=9):
rol=1
while(rol<=row):
print (rol,"*",row,"=",row*rol," ",end="")
rol=rol+1
print ()
row=row+1

 修改:
print (rol,"*",row,"=",row*rol," ",end="") 为:
print (str(rol)+"*"+str(row)+"="+str(row*rol),end="\t")

 

 

打印金字塔

row=1                       #控制循环的次数 同行书一致
while row<=4:
i=row                        #i控制#号个数
t=i*2-1                      #t控制*号个数
while 4-i>=1:
print("#",end="")       #end作用打印完不换行
i=i+1
while t>=1:
print("*",end="")
t=t-1
print()                      #打印完一行后,打印换行
row=row+1

 

 

 

 

posted on 2019-09-26 13:59  bsduan  阅读(382)  评论(0)    收藏  举报

导航