Move History

Rooted by: RPG Game
Fork Selected
  • Code
    def Complicated_Greetings(name):
        # using the orignial logic to make it more readable. 
        h=["H","e","l","l","o"]
        c=","
        w=["W","o","r","l","d"]
        e="!"
        k=""
        # build each term
        hello= ''.join(h)                               #create string from list
        comma= ' ' if name else c+ ' '                  #whitespace, or comma plus whitespace
        world= ''.join(w) if not name else ""           #create string from list or nothing
        name= name if name else ''                      #name or nothing
        exclamation= e* 2 if not name else ""           #two exclamations or nothing
        
        return hello+ comma+ world+ name+ exclamation   #build the final string and return it
    Test Cases
    import codewars_test as test
    # TODO Write tests
    import solution # or from solution import example
    
    # test.assert_equals(actual, expected, [optional] message)
    @test.describe("Brand New Triple A RPG Game")
    def test_group():
        @test.it("Check with name")
        def test_case():
            test.assert_equals(Complicated_Greetings("Femi"), "Hello Femi")
        @test.it("Check without name")
        def test_case():
            test.assert_equals(Complicated_Greetings(""), "Hello, World!!")
    
  • Code
    • def Complicated_Greetings(name):
    • # using the orignial logic to make it more readable.
    • h=["H","e","l","l","o"]
    • c=","
    • w=["W","o","r","l","d"]
    • e="!"
    • k=""
    • for i in h:
    • k+=i
    • if name=="":
    • k+=c
    • k+=" "
    • for i in w:
    • k+=i
    • k=k+e+e
    • else:
    • k+=" "
    • k+=name
    • return k
    • # build each term
    • hello= ''.join(h) #create string from list
    • comma= ' ' if name else c+ ' ' #whitespace, or comma plus whitespace
    • world= ''.join(w) if not name else "" #create string from list or nothing
    • name= name if name else '' #name or nothing
    • exclamation= e* 2 if not name else "" #two exclamations or nothing
    • return hello+ comma+ world+ name+ exclamation #build the final string and return it