Tuesday, December 24, 2024

Christmas tree and star in Python

def draw_tree(height):

  for i in range(1, height + 1):

    for j in range(height - i):

      print(" ", end="")

    for j in range(2 * i - 1):

      print("*", end="")

    print()

  for ctr in range(height // 2):

    print("*".center(height * 2))


h = int(input("Enter height of tree: "))

draw_tree(h)

==========================================================

import turtle as t

import time


win = t.Screen()

t.width(3)

t.ht()

t.speed(10)


fgColors = ['red', 'green', 'black', 'gold', 'blue']

bgColors = ['white', 'black', 'gold', 'black', 'black']


t.pu()

t.bk(100)

t.pd()


for i in range(5):

  t.color(fgColors[i])

  t.bgcolor(bgColors[i])

  for j in range(5):

    t.forward(200)

    t.right(144)

  t.write("   Happy Christmas", font=("Verdana", 15, "normal"))

  time.sleep(1.5)

  t.clear()


No comments:

Post a Comment