When an action shall be 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 be given for the plaintiff, it may be for such amount or less, in the discretion of the court, in proportion to the offense.