Be it further enacted that the mayor and council of said city shall have the right and authority, by ordinance, to prohibit idling, loitering, and loafing on the streets, alleys, lanes, squares, and sidewalks of said city, or upon any of them, and to prohibit the idling, loitering, and loafing in any of the public buildings in said city, and to prescribe penalties for the violation thereof.