Challenge 3: Printing Pyramid
Explore how to use for loops in Perl to print a half pyramid pattern of the letter 'a'. This lesson helps you practice loop structures and managing output lines, reinforcing your understanding of Perl loops and console output formatting.
We'll cover the following...
We'll cover the following...
Problem statement
Write code which prints half a pyramid of the alphabet a.
- The code takes an integer variable
$rowsas input and prints the pyramid with that number of rows displayinga.
Hint: Use
forloops to implement the solution.
Input
An integer.
Output
Print the character a on the console.
Sample input
$rows is equal to 5.
Sample output
Note: In order to move values to next line you can use
\n.
Coding challenge
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!