Ad
Code
Diff
  • 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
    • 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