Is it possible to put an if statement into the scripted expression of a driver?
A Python expression you can use is:

valueIfTrue if isConditionTrue else valueIfFalse


This is known as a ternary conditional operator see:
https://stackoverflow.com/questions/394809/ternary-conditional-operator-in-python