When an action is commenced for a penalty that by law is not to exceed a certain amount, the action may be commenced for that amount, and, if the judgment is given for the plaintiff, it may be for that amount or less, in the discretion of the court, in proportion to the offense.