Ad

102 bytes

Code
Diff
  • Greeting=lambda n,rank='',formal=0:f"He{['y','llo'][f:=formal]},{f' {rank}'*(rank*f>'')} {n}{'!.'[f]}"
    • Greeting=lambda n,rank='',formal=0:f"He{['y','llo'][a:=formal]},{f' {b}'if(b:=rank)*a else''} {n}{'!.'[a]}"
    • Greeting=lambda n,rank='',formal=0:f"He{['y','llo'][f:=formal]},{f' {rank}'*(rank*f>'')} {n}{'!.'[f]}"