legb rule in python example