Lois gives 40 / 4 = <<40/4=10>>10 books to her nephew
Then Lois has 40 - 10 = <<40-10=30>>30 books
Lois donates 30 / 3 = <<30/3=10>>10 books to the library
Then Lois has 30 - 10 = <<30-10=20>>20 books
After purchasing new books, Lois has 20 + 3 = <<20+3=23>>23 books
#### 23