We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For all of you who don't understand rocket science this solution will be the most understandable (i think)
# coMaByc.ljust(ile?, czego?), rjust, center - notes from last challengen=list(map(int,input().split()))#gettinguserinputasanintigerlist(index0-height,index1-width)thing=".|."#declaringvariablesforbetterreading(afterreducioncodehad8lines)dash="-"#--__--text="WELCOME"#--__--foriinrange(1,n[0],2):#doingaforloopforthetoppartofthemat(startingat1tohave1.|.thinginfirstliteration)print((i*thing).center(n[1],dash))#FirstIdoi*thing,whichiscalculatinghowmanythingsiwanttohavecoveredwiththedashes.ThenIdocentertoputthismanythingsinthecenterofthecover.Thenido(n[1],dash)tocoverthesethingswithdashes(I'mdoingn[1]becausethefunctionacctuallydoesacalcandkeepsthewidthofthestringinacontroledsize{n[1]})print(text.center(n[1],dash))#Thisisprintingourtext,whichisWELCOMEalsocoveringitwithdashesandthewidthofthewholelineisn[1]forjinrange(n[0],-1,-2):#NowI'mdoingthesamethingasabove,butreversed.Iputn[0]infirst,thenIchange1to-1and2to-2.Justreversingeverythingtoalsomakethepiramidreversedifj!=n[0]:#MaybeskillissuebutIwanttoavoidthefirstliteration,whichwillbeallthingswithnodashes.Ifyouhaveanideahowtodothispartwithouttheifstatementucancomment.I'm15andlookingforopportunitiestoimprove.Correctionaprecieated(andaenglishgrammarbookasagiftfromallbritishreaders)print((j*thing).center(n[1],dash))#It's1:1thesameasthefirstprintinthiscode.Idon'thavetoexplainitagain(ithink)# HOMEWORK (hehe)# If you have not done the Text Alignment challenge on this loveley platform NOW GO AHEAD AND DO IT. It'll perfectly teach you how to use this center/ljust and rjust things. After that challange you should be doing this.# Practise operations on strings. If you get new knowlage (maybe my 15-yr old explanation helped you understand someting or you saw a new pattern) you shound practise it as the 30:2 rule says: for every 30 minutes of reading/tutorial watching you should do 2h of practise (just 4x more).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Designer Door Mat
You are viewing a single comment's thread. Return to all comments →
Beginner friendly full comented code
Passes all testcases!
For all of you who don't understand rocket science this solution will be the most understandable (i think)