LAST FALL, President Obama threw what was billed as the first White House Science Fair, a photo op in the gilt-mirrored State Dining Room. He tested a steering wheel designed by middle schoolers to detect distracted driving and peeked inside a robot that plays soccer. It was meant as an inspirational moment: children, science is fun; work harder.

Politicians and educators have been wringing their hands for years over test scores showing American students falling behind their counterparts in Slovenia and Singapore. How will the United States stack up against global rivals in innovation? The president and industry groups have called on colleges to graduate 10,000 more engineers a year and 100,000 new teachers with majors in STEM — science, technology, engineering and math. All the Sputnik-like urgency has put classrooms from kindergarten through 12th grade — the pipeline, as they call it — under a microscope. And there are encouraging signs, with surveys showing the number of college freshmen interested in majoring in a STEM field on the rise.

But, it turns out, middle and high school students are having most of the fun, building their erector sets and dropping eggs into water to test the first law of motion. The excitement quickly fades as students brush up against the reality of what David E. Goldberg, an emeritus engineering professor, calls “the math-science death march.” Freshmen in college wade through a blizzard of calculus, physics and chemistry in lecture halls with hundreds of other students. And then many wash out.

Studies have found that roughly 40 percent of students planning engineering and science majors end up switching to other subjects or failing to get any degree. That increases to as much as 60 percent when pre-medical students, who typically have the strongest SAT scores and high school science preparation, are included, according to new data from the University of California at Los Angeles. That is twice the combined attrition rate of all other majors.