Ad

-6, 96 bytes

Code
Diff
  • Greeting=lambda n,rank='',formal=0:f"He{['y','llo'][f:=formal]},{rank*f and' '+rank} "+n+'!.'[f]
    • 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'][f:=formal]},{rank*f and' '+rank} "+n+'!.'[f]