Text Alignment

Design HackerRank Logo

Use of ljust(), rjust() and centre() from string in Python.

Generate a logo as shown below,

Task

Problem: https://www.hackerrank.com/challenges/text-alignment/problem
You are given a partial code that is used for generating the HackerRank Logo of variable thickness. 
Your task is to replace the blank (______) with rjust(), ljust() or center().

Solution:

  • Top Cone
thickness=5
 c='H'
 for i in range(thickness):
     print((ci).rjust(thickness-1)+c+(ci).ljust(thickness-1))
    H    
   HHH   
  HHHHH  
 HHHHHHH 
HHHHHHHHH
  • Top Pillars
for i in range(thickness+1):
    print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6))
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH 
  • Middle Belt
for i in range((thickness+1)//2):
    print((c*thickness*5).center(thickness*6)) 
  HHHHHHHHHHHHHHHHHHHHHHHHH   
  HHHHHHHHHHHHHHHHHHHHHHHHH   
  HHHHHHHHHHHHHHHHHHHHHHHHH 
  • Bottom Pillars
for i in range(thickness+1):
    print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) 
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
           
  • Bottom Cone
for i in range(thickness):
    print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-        1)).ljust(thickness)).rjust(thickness*6))
                    HHHHHHHHH 
                     HHHHHHH  
                      HHHHH   
                       HHH    
                        H     
  • Final
#Replace all ______ with rjust, ljust or center. 

thickness = int(input()) #This must be an odd number
c = 'H'

#Top Cone
for i in range(thickness):
    print((c*i).rjust(thickness-1)+c+(c*i).ljust(thickness-1))

#Top Pillars
for i in range(thickness+1):
    print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6))

#Middle Belt
for i in range((thickness+1)//2):
    print((c*thickness*5).center(thickness*6))    

#Bottom Pillars
for i in range(thickness+1):
    print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6))    

#Bottom Cone
for i in range(thickness):
    print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-1)).ljust(thickness)).rjust(thickness*6))

Output:

    H    
   HHH   
  HHHHH  
 HHHHHHH 
HHHHHHHHH
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHHHHHHHHHHHHHHHHHHHHHH   
  HHHHHHHHHHHHHHHHHHHHHHHHH   
  HHHHHHHHHHHHHHHHHHHHHHHHH   
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
  HHHHH               HHHHH             
                    HHHHHHHHH 
                     HHHHHHH  
                      HHHHH   
                       HHH    
                        H 


119 Comments

  1. Denny said:

    Stunning story there. What occurred after?
    Thanks!

    March 9, 2021
    Reply
  2. agen mega888 said:

    This is the right web site for anyone who wants to
    understand this topic. You know a whole lot
    its almost hard to argue with you (not that I personally
    will need to…HaHa). You certainly put a fresh spin on a topic which has been written about for ages.
    Great stuff, just excellent!

    My blog post – agen mega888

    March 9, 2021
    Reply
  3. I constantly emailed this blog post page to all my friends, for
    the reason that if like to read it afterward
    my contacts will too.

    my webpage pussy888 for pc

    March 9, 2021
    Reply
  4. Saya telah menjelajah online lebih dari tiga jam hari ini, namun saya
    tidak pernah menemukan artikel menarik seperti milik Anda.
    It is cukup berharga bagi saya. Menurut pendapat saya , jika semua pemilik situs
    dan blogger membuat konten yang baik seperti yang Anda
    lakukan, web akan menjadi lebih berguna dari sebelumnya.

    Also visit my webpage … Situs judi slot joker terbaru

    March 9, 2021
    Reply
  5. 918kiss pc said:

    continuously i used to read smaller articles that as well clear their motive, and that
    is also happening with this paragraph which I am
    reading here.

    My webpage 918kiss pc

    March 9, 2021
    Reply
  6. I’m really loving the theme/design of your blog. Do you ever run into any web browser compatibility issues?
    A handful of my blog readers have complained about my blog
    not working correctly in Explorer but looks great in Safari.
    Do you have any recommendations to help fix this problem?

    my web page … 918kiss iphone

    March 9, 2021
    Reply
  7. Hello, I check your new stuff like every week.
    Your writing style is witty, keep doing what you’re
    doing!

    Check out my page: 918kaya android; losttower.icu,

    March 9, 2021
    Reply
  8. If you would like to increase your knowledge simply keep visiting
    this website and be updated with the most recent news update posted here.

    Review my site mega888 test id

    March 9, 2021
    Reply
  9. Thanks for your personal marvelous posting! I definitely enjoyed reading it, you could be
    a great author. I will remember to bookmark your blog and
    will come back later in life. I want to encourage
    continue your great writing, have a nice afternoon!

    my web site – 918kaya Apk android

    March 10, 2021
    Reply
  10. Hi there! I just would like to give you a big thumbs up for the great info you’ve got right
    here on this post. I will be coming back to your web site for more soon.

    Feel free to visit my web blog :: xe88 support teams

    March 10, 2021
    Reply
  11. xe88 bingo said:

    Asking questions are genuinely fastidious thing if you are not understanding anything
    totally, however this paragraph gives good understanding yet.

    Feel free to surf to my webpage xe88 bingo

    March 10, 2021
    Reply
  12. I like what you guys tend to be up too. This sort of clever work and
    coverage! Keep up the excellent works guys
    I’ve incorporated you guys to our blogroll.

    my web blog: mega888 download

    March 10, 2021
    Reply
  13. pussy888 apk said:

    We’re a group of volunteers and opening a new scheme in our community.

    Your website provided us with valuable info to work on. You’ve done
    an impressive job and our whole community will be thankful to you.

    Take a look at my web site – pussy888 apk

    March 10, 2021
    Reply
  14. Slot Mega888 said:

    Have you ever considered creating an e-book or guest authoring on other blogs?
    I have a blog based on the same topics you discuss and would really like to have you share
    some stories/information. I know my readers would value your work.
    If you are even remotely interested, feel free
    to shoot me an email.

    Feel free to visit my homepage; Slot Mega888

    March 10, 2021
    Reply
  15. Heya i am for the first time here. I found this board and
    I find It really useful & it helped me out a lot.
    I am hoping to present something again and aid others
    like you aided me.

    my website: 918kaya online

    March 10, 2021
    Reply
  16. jin.ne.jp said:

    Hi, i read your blog occasionally and i own a similar one and i was just wondering if you get
    a lot of spam responses? If so how do you protect against it, any plugin or anything you can recommend?

    I get so much lately it’s driving me crazy so any assistance is very much appreciated.

    Feel free to visit my blog – 918kaya kiosk – jin.ne.jp

    March 10, 2021
    Reply
  17. gameaco.com said:

    Saya telah menjelajah online lebih dari 4 jam hari ini, namun saya tidak pernah
    menemukan artikel menarik seperti milik Anda. It is cukup
    berharga bagi saya. Dalam pandangan saya, jika semua pemilik web dan blogger membuat konten yang baik seperti yang Anda lakukan, web akan menjadi
    a jauh lebih berguna dari sebelumnya.

    Look into my web site Joker128 pc [gameaco.com]

    March 10, 2021
    Reply
  18. Have you ever considered about adding a little bit more than just your articles?
    I mean, what you say is important and all. Nevertheless think of if
    you added some great photos or video clips to give your posts more, “pop”!
    Your content is excellent but with pics and videos,
    this site could certainly be one of the very best in its field.
    Awesome blog!

    Also visit my web-site; 918kaya game; hasyim.man1jember.sch.id,

    March 10, 2021
    Reply
  19. Susanne said:

    Wow! At last I got a website from where I know how to actually obtain helpful facts regarding my study and knowledge.

    March 10, 2021
    Reply
  20. JasonNox said:

    viagra discount viagra price
    where to buy viagra

    March 12, 2021
    Reply
  21. Waynetriag said:

    where to buy viagra online viagra from india
    viagra over the counter walmart

    March 13, 2021
    Reply
  22. Ricardomum said:

    cheap diflucan online diflucan 125mg
    prescription drugs without doctor approval

    March 16, 2021
    Reply
  23. Terrymaymn said:

    prescription drugs online cheap ed pills usa
    ed pills without a doctor prescription

    March 22, 2021
    Reply
  24. Marvinwag said:

    discount neurontin: gabapentin – neurontin 2400 mg

    March 26, 2021
    Reply
  25. Marvinwag said:

    buy neurontin 100 mg: gabapentin – neurontin 100 mg tablets

    March 27, 2021
    Reply
  26. xe88 said:

    If some one needs expert view concerning blogging then i propose him/her to go to see this
    web site, Keep up the nice work.

    Also visit my web site … xe88

    March 28, 2021
    Reply
  27. xe88 apk said:

    Hello, I desire to subscribe for this blog to get hottest
    updates, therefore where can i do it please help out.

    Feel free to visit my site: xe88 apk

    March 29, 2021
    Reply
  28. CharlesPar said:

    prescriptions from india: meds from india india pharmacies shipping to usa

    April 5, 2021
    Reply
  29. Alfredskach said:

    erectile pills canada: levitra pills male erectile pills

    April 8, 2021
    Reply
  30. Claudmam said:

    diflucan 200 mg price: diflucan generic – diflucan canadian pharmacy

    April 16, 2021
    Reply
  31. Güvenilir Takipçi Satın Alınabilir Site
    en iyi siteden takipçi al seçenekleri bireylerin beklentilerine göre
    çok çok detaylı olabilmektedir.
    Herkesin Instagrama hesabında değişik bir gaye ve beklentiyle takipçi miktarını çoğaltmak
    istemesi söz konusudur.
    Bunların hepsine hitap edebilecek hizmetlerin sunulması ile birlikte en iyi instagram Takipçi Satın Al sitesinden takipçi almaktır.

    Site üzerinden 1.000, 2.000 bu rakamların fazlası yada azı dilediğiniz kadar en iyi siteden takipçi alabilirsiniz

    April 18, 2021
    Reply
  32. Asking questions are actually fastidious thing if you are not understanding something entirely,
    however this paragraph presents nice understanding yet.

    April 18, 2021
    Reply
  33. RafaelLeree said:

    lasix dosage: buy lasix – lasix 40mg

    April 19, 2021
    Reply
  34. RafaelLeree said:

    generic for paxil: cheap paxil – generic for paxil

    April 19, 2021
    Reply
  35. RafaelLeree said:

    paxil flu: cheap paxil – paxil for depression

    April 20, 2021
    Reply
  36. Thomaswatte said:

    cheapest on line valtrex without a prescription: valtrex for sale – valtrex online canada
    tadalafil generic cost

    April 21, 2021
    Reply
  37. Thomaswatte said:

    ventolin us price: buy ventolin – order ventolin online canada
    tadalafil 20mg for sale

    April 21, 2021
    Reply
  38. Thomaswatte said:

    price of valtrex in india: cheap valtrex – valtrex uk pharmacy
    tadalafil pills

    April 22, 2021
    Reply
  39. Thomaswatte said:

    buy generic valtrex online canada: buy valtrex – valtrex 500 cost
    tadalafil without a doctor’s prescription

    April 23, 2021
    Reply
  40. Thomaswatte said:

    buy cheap ventolin: ventolin for sale – ventolin online australia
    tadalafil 20mg for sale

    April 24, 2021
    Reply
  41. Robertevino said:

    ed treatment drugs ed pills – cures for ed
    best otc ed pills

    April 26, 2021
    Reply
  42. VictorPOORM said:

    reliable rx pharmacy ed pills – canadian pharmacies that deliver to the us
    legitimate canadian pharmacies

    April 29, 2021
    Reply
  43. VictorPOORM said:

    cheap viagra online canadian pharmacy indian pharmacy – online pharmacy no prescription
    viagra from canadian pharmacy

    April 29, 2021
    Reply

Leave a Reply

Your email address will not be published.