python学习定义一个类和方法用while打印出星号塔day10/下午

 

class Paint():
    def paintStar(self):
        i=1
        while i<6:
            j=1
            while j<=5-i:
                print(" ",end="")
                j+=1
            j=1
            while j<=2*i-1:
                print("*",end="")
                j+=1
            print()
            i+=1
p=Paint()
p.paintStar()

 

class Paint():
    def paintStar(self):
        i=1
        while i<7:
            j=1
            while j<=6-i:
                print(" ",end=" ")
                j+=1
            j=1
            while j<=2*i-1:
                if j==1 or j==2*i-1 or i==6 or i==4 or j==i:
                    print("*",end=" ")
                else:
                    print(" ",end=" ")
                j+=1
            print()
            i+=1
p=Paint()
p.paintStar()

猜你喜欢

转载自blog.csdn.net/qq_39112101/article/details/88065872