Set Task Custom Field to X if Related to a Lead

Set Task Custom Field to X if Related to a Lead

We have a custom field in our Activities / Task module called "Category". Example value would be "X" or "Y".

How do we automatically set the value to "X" if the Activity or Task is related to a Lead, and to "Y" if it's related to a Deal?