The title of your post was "D40 vs K100D" - why is there then mention of Canon? I guess because this is a Canon camp.
$700 for a D40? Jenny just got me one and it was on sale at Bing Lee for just over $1,000 for the 18-55 kit. Is that for just the body then?
Anyway - I'm genuinely starting to love my D40. It is full of features that aren't "fanfared", and it takes time to learn about a lot of them. The handling of the camera is superb, being as small and light as it is.
Why would you but a second-hand camera for nearly what you'd pay for a new one? If it's mainly for terrestrial use then a 2nd hand 350D should be considered too old IMHO. Get a warrany!!!!
Here's a great place to start - Ken Rockwell's comparison chart - from a guy who has actually USED all of these cameras and is not just propagating other people's opinions based on their biased brand loyalty.
http://www.kenrockwell.com/tech.htm#cameras
Anyway - I'm sure the Pentax is a good camera too, but read these two reports before you decide:
D40-specific test:
http://www.kenrockwell.com/nikon/d40.htm
http://www.bythom.com/d40review.htm