Course Content
Python Functions Tutorial
1. What is Function in Python?
3. Function Return Value Specification
Python Functions Tutorial
Challenge: Pyramid
Task
Write a recursive function draw_pyramid
that takes an integer height
and prints a pyramid of asterisks with a height of height
to the console.
Expected Output:
Conditions:
- To solve this task, you need to use a recursive approach.
- The input number
height
should be positive. - The pyramid is formed using the '*' symbol and spaces. Each row of the pyramid should have
2 * height - 1
characters (asterisks or spaces). - The top row should have one asterisk, the next row should have three, and so on, increasing the number of asterisks by two in each new row.
- All asterisks should be centered in the rows using spaces.
- The pyramid should be printed using the
print
function.
Everything was clear?
Section 4. Chapter 2