初学python求组队之用python画一个圣诞树,祝大家圣诞快乐!

程序:
def paintleaves(m):
    for i in range(m):
        if(i == 10):
            print( ' '*(m-i) + '*'*( 2*i + 1-len( 'happy Christmas')) + 'happy Christmas'+ ' '*(m-i))
            continue
        if(i == 20):
            print( ' '*(m-i) + '*'*( 2*i + 1-len( 'happy Christmas')) +'happy Christmas'+ ' '*(m-i))
            continue
        if(i == m-1):
            print( ' '*(m-i) + 'happy Christmas'+ '*'*( 2*i + 1-len( 'happy Christmas')) + ' '*(m-i))
            continue   
        print(' '*(m-i) + '*'*(2*i + 1) + ' '*(m-i))   

def paintTrunk(n):
    for j in range (8 ):
       print(' '*(n - 5) + '*'*10 + ' '*(n - 5))


paintleaves(30)
paintTrunk(30)

效果图:

初学python求组队之用python画一个圣诞树,祝大家圣诞快乐!_第1张图片

你可能感兴趣的:(python之旅)