OK - Pentax K100D uses AA batteries, so you would need to invest in a charger and a good set of Ni-Mh batteries, otherwise things could start to get expensive! Does, however, have the advantage that with the built-in shake reduction, any lens you put on it automatically becomes an image-stabilised lens.
D40 and D40X, on the other hand, do come with a rechargeable li-ion battery and charger. The downside, is that it will only autofocus with AF-S lenses, or Sigma HSM lenses, as it does not have a built-in focussing motor, unlike the D80/100/200 etc., so does limit the choice of lenses, although Nikon have introduced a few reasonably priced AF-S lenses, such as the 55-200VR, which isn't a bad little lens.
As has already been mentioned, the Canon EOS400D is quite a good camera, with a huge range of lenses available for it, both new and second-hand!
Hope this helps.....