top of page
  • Pinterest
  • Facebook
  • Instagram

ChristmasTree

  • Writer: Lim Long Teck
    Lim Long Teck
  • Dec 30, 2021
  • 1 min read

Write a program to prompt the user for a character and a number, and then print a Christmas tree accordingly.


Program:

char = input('Enter a character: ')

num = int(input('Enter a number: '))

for i in range(num):

line = ''

line += ' ' * (num - 1)

for i in range(i+1):

line += char

line += ' '

print(line)

num -= 1


Output:

Enter a character: *

Enter a number: 5

*

* *

* * *

* * * *

* * * * *


----------------------------------------------------or---------------------------------------------


Enter a character: +

Enter a number: 9

+

+ +

+ + +

+ + + +

+ + + + +

+ + + + + +

+ + + + + + +

+ + + + + + + +

+ + + + + + + + +

Recent Posts

See All
CountLetters

Write a Python program to - Prompt user to input a sentence - Count the occurrence of each letter in the input sentence - Save the result...

 
 
 
BirthdayParadox

The Birthday Paradox asks the question, “If you asked random people their birthday, how many people do you expect to ask before you find...

 
 
 
NumberGuessing

Write a program that simulates a number guessing game. It first generates a random number between 1 and 100. It then prompts user to...

 
 
 

Commentaires


bottom of page