Python Forum

Full Version: Pyramid of leters of n levels
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
PirĂ¡mide de Letras de n niveles
Iam asked to write a program in python that uses the for function to print a pyramid of leters of n levels.
To obtain the levels of the pyramid the code must ask for a number between 1 and 26.

Example:

The code must return the following pyramid when the input is 3:

A

A B A

A B C B A

Can you help to figure out how to do this, im learning python and so far the teacher hasn't showed us how to do something like this
Moved to homework forum for obvious reasons.

I could not imagine that an instructor would give a question to something they have not instructed on how to do. Aside from that, what have you tried so far?
Well, I haven't tried coding it yet but i've been thinking about making making a for statement that then compares de i so it can enter trough multiple if cases and then print them. Something like


control = int(input())
for i in range (1, control+1):
    if i == 1:
       print('      A      ')
    if i == 2:
       print('    A B A    ')
and so on
Couple things - your coding would center the pyramid, while your example of the desired output is left justified. Both possible, latter easier, which is it?
And, have you been taught/can you use lists?
Finally, your code would print the pyramid upside down, printing the A first, then the ABA, etc.
You print a certain number of spaces and then the letter(s). The next line prints fewer spaces and more letters. Rinse and repeat.