Can this code be shortened using variables?

Yes

(It's nearly always possible. In this case, definitely!)