With phrase.strip in a variable.
    
    
    import std/strutils
    
    func hey(phrase: string): string =
      let phrase = phrase.strip
      if phrase == "":
        "Fine. Be that way!"
      elif UppercaseLetters in phrase and LowercaseLetters notin phrase:
        if phrase.endsWith('?'):
          "Calm down, I know what I'm doing!"
        else:
          "Whoa, chill out!"
      elif phrase.endsWith('?'):
        "Sure."
      else:
        "Whatever."
    
    
    Run

With boolean variables.
    
    
    import std/strutils
    
    func hey(phrase: string): string =
      let phrase = phrase.strip
      let isEmpty = phrase.len == 0
      if isEmpty:
        "Fine. Be that way!"
      else:
        let allCaps = UppercaseLetters in phrase and LowercaseLetters notin 
phrase
        let isQuestion = phrase.endsWith('?')
        if allCaps:
          if isQuestion:
            "Calm down, I know what I'm doing!"
          else:
            "Whoa, chill out!"
        elif isQuestion:
          "Sure."
        else:
          "Whatever."
    
    
    Run

Surely one of these is good enough now? If not, say why and I'll change it.

Reply via email to