there are about 4 or 5 different nikkor 50mm lenses.... only one of which will autofocus on the D40/60/5000
the one that will autofocus on your camera is the AF-S NIKKOR 50mm f/1.4G, and of course it's the most expensive next to the NIKKOR 50mm f/1.2, which won't autofocus or meter on your camera.
the AF NIKKOR 50mm f/1.4D and the AF NIKKOR 50mm f/1.8D are the most commonly purchased of the nikkor 50mm lenses and are fully functional on your camera except for autofocus.
which one should you get? if you're ok with manual focus and don't have a budget then get the AF NIKKOR 50mm f/1.4D
if you're ok with manual focus but you're on a budget then get the AF NIKKOR 50mm f/1.8D
if you're not ok with manual focus then you're screwed, you're stuck with the AF-S NIKKOR 50mm f/1.4G
something else to consider.... the "nifty fifty" is a common lens because it's considered a "normal" or "standard" focal length. this is when it's used on a Full Frame (FX) or Film camera. nikon released the AF-S DX NIKKOR 35mm f/1.8G which is considered the "normal" or "standard" for APS-C (DX) format. so you might want to look at that lens as well, it will autofocus on your camera.