Ad

Compact again, we need the storage space!

Code
Diff
  • Greeting=lambda n,rank="",formal=0:f"He{['y','llo'][formal]}, {['',f'{rank} '][bool(rank and formal)]}{n}{chr(33+13*formal)}"
    
    • def Greeting(name, rank=None, formal=False):
    • greeting_style = "Hello" if formal else "Hey"
    • rank_part = f"{rank} " if rank and formal else ""
    • punctuation = '.' if formal else '!'
    • return f"{greeting_style}, {rank_part}{name}{punctuation}"
    • Greeting=lambda n,rank="",formal=0:f"He{['y','llo'][formal]}, {['',f'{rank} '][bool(rank and formal)]}{n}{chr(33+13*formal)}"

Compact, can't be taking up too much storage space!

Code
Diff
  • class Greeting:
        def __init__(self, name, rank=None, formal=False):
            self.name = name
            self.rank = rank
            self.formal = formal
            
        def __call__(self):
            return f'He{["y","llo"][self.formal]}, {[str(self.rank)+" ",""][self.rank is None or not self.formal]}{self.name}{chr(33+self.formal*13)}'
    • class Greeting:
    • def __init__(self, name, rank=None, formal=False):
    • self.name = name
    • self.rank = rank
    • self.formal = formal
    • def __call__(self):
    • if self.formal: return f'Hello,{" " + self.rank if self.rank is not None else ""} {self.name}.'
    • else: return f'Hey, {self.name}!'
    • return f'He{["y","llo"][self.formal]}, {[str(self.rank)+" ",""][self.rank is None or not self.formal]}{self.name}{chr(33+self.formal*13)}'