The theoretical definition of the probability is
1. The number of all possible outcomes.
You have 5 letters. The first letter of the code can be chosen in 5 ways, the second - in 4 ways, the third - in 3 ways, the fourth letter - in 2 ways and the last one - in 1 way. In total, the number of all possible outcomes is
2. The number of all favorable outcomes.
If the code starts with M and ends with E, then you can change only second, third and fourth letters of the code. The second letter can be chosen in 3 ways (from letters A, F and R), the third letter - in 2 ways and the fourth letter - in 1 way. In total, the number of all favorable outcomes is
Then the probability is