Printing an ASCII diamond with set width in python

前端 未结 7 1700
Happy的楠姐
Happy的楠姐 2020-12-11 13:50

Yes, this is a homework task. But just please, if you\'re going to give me the code please tell me what you\'ve done in detail. I am extremely new to this.

So the ta

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 14:20

    check it out (for python 2.7x) :


    Filled ASCII Diamond :

    width = 1
    width += int(raw_input('Width : '))
    for i in range (1,width):
        for j in range (width,i,-1):
            print " ",
        for j in range (1,i,1):
            print " * ",
        print
    
    for i in range (width,1,-1):
        for j in range (width,i,-1):
            print " ",
        for j in range (1,i,1):
            print " * ",
        print
    

    This works!! But not in any Browser window . . .

提交回复
热议问题