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