Designer Door Mat

  • + 0 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)

    # coMaByc.ljust(ile?, czego?), rjust, center - notes from last challenge
    n = list(map(int, input().split())) # getting user input as an intiger list (index 0 - height, index 1 - width)
    
    thing = ".|." # declaring variables for better reading (after reducion code had 8 lines)
    dash = "-" # --__--
    text = "WELCOME" # --__--
    
    for i in range(1, n[0], 2): # doing a for loop for the top part of the mat (starting at 1 to have 1 .|. thing in first literation)
        print((i * thing).center(n[1], dash)) # First I do i * thing, which is calculating how many things i want to have covered with the dashes. Then I do center to put this many things in the center of the cover. Then i do (n[1], dash) to cover these things with dashes (I'm doing n[1] because the function acctually does a calc and keeps the width of the string in a controled size {n[1]})  
        
    print(text.center(n[1], dash)) # This is printing our text, which is WELCOME also covering it with dashes and the width of the whole line is n[1]
    
    for j in range(n[0], -1, -2): # Now I'm doing the same thing as above, but reversed. I put n[0] in first, then I change 1 to -1 and 2 to -2. Just reversing everything to also make the piramid reversed
        if j != n[0]: # Maybe skill issue but I want to avoid the first literation, which will be all things with no dashes. If you have an idea how to do this part without the if statement u can comment. I'm 15 and looking for opportunities to improve. Correction aprecieated (and a english grammar book as a gift from all british readers)
            print((j * thing).center(n[1], dash)) # It's 1:1 the same as the first print in this code. I don't have to explain it again (i think)
            
    
    # 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).