Python Forum
Pyramid of leters of n levels
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyramid of leters of n levels
#1
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
Reply
#2
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?
Recommended Tutorials:
Reply
#3
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
Reply
#4
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.
Reply
#5
You print a certain number of spaces and then the letter(s). The next line prints fewer spaces and more letters. Rinse and repeat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print a * pyramid drogers10940 5 4,713 Apr-26-2020, 09:25 PM
Last Post: prothej227
  Pyramid gamingingrs 1 2,293 Oct-16-2018, 02:56 PM
Last Post: j.crater
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 8,831 Apr-20-2018, 04:07 AM
Last Post: pythoneer
  Pyramid of Solitaires qwerty 1 3,465 Mar-22-2017, 04:10 PM
Last Post: nilamo
  Implementation Pyramid Solitaire qwerty 2 5,070 Feb-27-2017, 11:57 AM
Last Post: qwerty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020