Let x be the number of $1 bills and y be the number of $5 bills that Hermione had in her purse. Then we can write two equations based on the given information:
x + y = 12 (because Hermione had 12 bills in total)
x + 5y = 40 (because the total value of the bills was $40)
We can solve this system of equations by first solving the first equation for x:
x = 12 - y
Substituting this expression for x into the second equation, we get:
(12 - y) + 5y = 40
Simplifying and solving for y, we get:
4y = 28
y = 7
Therefore, Hermione had 7 $5 bills in her purse. Answer: 7.