Answer: 491
============================================
Step-by-step explanation:
Let's go with the example given to us. Let's say the correct lock combo is 4-2-7.
If we get the first two digits right, then we have 8 choices for the third digit since we pick from between 1 and 8 inclusive. There are 8 combos of the form 4-2-x.
The same goes for stuff of the form 4-x-7 and x-2-7.
There appear to be 8+8+8 = 24 different combos that will open this faulty lock. However, we must subtract off 2 because we've triple counted "4-2-7" when adding up those 8's.
In reality there are 24-2 = 22 different combos that will open the faulty lock.
There are 8^3 = 512 different combos total. That gives 512-22 = 490 combos that do not open the lock.
If the person is very unlucky, with the worst luck possible, then they would randomly try all of the 490 combos that don't work.
Attempt number 491 is when they'll land on one of the 22 combos that do work.