276. Python Program to Print a Letter Triangle
EasyPhase 1 · Warm-up
You know how a for loop goes through a string, and you know break. That is all you need here.
Overview
Letter patterns work like number patterns, but with letters. They show you how to go through a string one letter at a time.
Problem Statement
Yuki makes an alphabet chart for a reading class. Read a whole number n and print n rows. Row 1 is A, row 2 is AB, row 3 is ABC, and so on. Each row has one more capital letter than the row before it, with no spaces between the letters.
You can type the 26 capital letters into one string, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", and loop over it.
Steps
- Read
nand turn it into a whole number. - Make a string with the 26 capital letters, and an empty row.
- Loop over the letters. In each turn, add the letter to the row and print the row.
- Stop the loop when the row has
nletters.
Examples
Example 1. Input 4 gives:
A
AB
ABC
ABCD
Why: there are 4 rows, and the last row has the first 4 letters.
Example 2. Input 2 gives:
A
AB
Why: there are 2 rows. Row 2 is row 1 with a B added at the end.
Input
One whole number n, from 1 to 26 (the English alphabet has 26 letters). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
n lines. Line i holds the first i capital letters, with no spaces. Every line starts at the left edge, with no space in front. The tests try 5 different inputs.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.