There are several distinctions in Nikon lenses that affect their use on the D40 and any film body:
1. DX - The D40, along with most DSLRs, shoot a samller format than the standard 35mm film format. Nikon refers to this smaller format as DX. The DX format (the size of the D40's sensor) is about 1/2 the area of a standard 35mm film image (and what Nikon calls FX in a few of their high-end DSLRs). Any film lens will easily cover the smaller DX format, but DX lenses will not fill the larger film format with a usable image. You would have to crop to only the center portion of a film image if you used a DX lens on a film body.
2. G - G-series lenses do not have an f/stop ring. The f/stop is controlled from the body. A manual film body requires lenses that have f/stop rings.
3. AF-S and AF-I - The D40 (and D40x, D60, D3000, & D5000) do not have autofocus motors in the body. They rely on the lens having its own motor. Nikons AF-S and AF-I lenses have their own motors. The AF and AF-D lenses lack motors and won't autofocus on a D40. You have to focus manually. Manual focus film bodies, of course, ignore the AF differences.
4. Electronic Meter Coupling - The D40 requires this to meter. All AF lenses (any variant) and the few AI-P lenses have electronic meter coupling. Manual focus AI and AI-s lenses, only have mechanical meter coupling. The D40's exposure meter, whether used in an automatic setting or in manual, will not function with these MF lenses.
What camera models you should be considering is hard to say. The only new model is the FM10 which comes bundled with a 35-70 AI-s lens (no metering or AF on the D40). Its a decent student camera.
There are a number of good used models to consider, but buying used is something of a crap-shoot unless you can handle the camera before purchase and have some experience with cameras so that you can evaluate its condition. If you go this route, any Nikon FM variant (FM, FM2, FM2n, ...) would be a good consideration. The FE models are also good, though they have one autoexposure mode (aperture priority) in addition to manual. Most of the older Nikkormat/Nikomat models can be decent, but most pose some additional meter coupling issues, when mixing with more modern models, that a beginner shouldn't have to deal with.