Hadi Partovi and Ali Partovi, the founders of Code.Org, are encouraging U.S. schools to teach computer science. (Code.org/Code.org)

Hadi Partovi, retired at 38 after working for Microsoft and creating other tech companies, was figuring out what to do with the rest of his life.

After spending his career in computers, he was troubled by one fact: In this digital age, only about one in 10 U.S. schools teach computer science.

“I thought, ‘Why isn’t computer science being taught?’ ” said Partovi, who lives in Seattle and is an investor in a number of companies, including Zappos and Air­bnb.

Partovi and his twin brother, Ali, made a video to inspire students to learn computer science. “What Most Schools Don’t Teach,” starring Bill Gates, Mark Zuckerberg and other tech moguls, went viral on YouTube, and Partovi fielded requests from 10,000 school districts asking how they could incorporate computer coding into their classrooms.

A movement was born.

The Partovi brothers came up with “Hour of Code,” a Web site and campaign that offers free hour-long tutorials in computer coding for students in kindergarten through high school. Celebrities including President Obama to NBA star Chris Bosh to Ashton Kutcher promoted “Hour of Code” last month, giving it a glamorous sheen that’s absent from most education initiatives.

The results exceeded Partovi’s dreams. More than 20 million people around the world tried “Hour of Code,” 17 million of them in the United States. Half of the event’s participants were female, a significant development in a field dominated by men. “This was just incredible,” Partovi said. “It was a Sputnik moment.”

Now, Partovi is trying to harness the momentum and use it to expand computer science education in elementary and secondary schools.

“When I went to school, we learned how to dissect a frog,” said Partovi, now 41. “It’s equally important to know how to dissect an app, to know what a cookie is or what a GPS is. It’s important not just for people who want careers in computers, but for a future president, or a future journalist — anybody who is going to have a knowledge career.”

Of the country’s 42,000 schools, about 3,400 offer computer science classes, said Fred Humphries, vice president for government affairs at Microsoft. The tech giant has been pushing for federal and state policies to encourage computer science education.

Part of the problem is misunderstanding what it means to study computer science, said Chris Stephenson, executive director of the Computer Science Teachers Association.

“State officials will say, ‘I know our students are learning computer science because we have a lab of computers in every school,’ ” Stephenson said. “There’s an assumption because students are using this technology, they have the knowledge to build this technology, and they don’t. We’re creating consumers of technology rather than builders of technology.”

Partovi has raised $10 million to create code.org, a nonprofit organization aimed at changing policy on the federal, state and local levels to expand access to computer science in K-12. In its effort, Code.org is joined by a range of partners, including Microsoft, Google, Amazon, the College Board and the Computer Science Teachers Association.

“Hour of Code has created a level of awareness beyond anything we could have hoped for,” Stephenson said. “Getting people from ‘There’s a problem’ to ‘Let’s do something about it’ is a huge move.”

A top priority for Code.org’s coalition is to persuade school districts to count computer science courses toward graduation requirements. When computer science classes are considered an elective, fewer students are likely to enroll, Stephenson said.

“The kids who want to go to university or even community college are so laser-focused on what it takes to get them there,” Stephenson said. “Taking credits that don’t count toward graduation are not worth it to them.”

In September 2012, nine states and the District of Columbia counted computer science courses toward graduation requirements. That number has grown to 17 states, including Maryland. Stephenson expects a “bumper crop” of more states this year.

Code.org has agreements with several school districts, including New York and Chicago, to provide free professional training for teachers and supply curriculum materials, Partovi said.

One of Code.org’s goals is to attack the dearth of female and minority students in computing classes, Partovi said.

According to the College Board, of the 29,555 students who took the Advanced Placement Computer Science test in 2013, about 19 percent were female, 8 percent were Hispanic and 4 percent were black. No females took the exam in Mississippi, Montana and Wyoming. And no blacks took the exam in Alaska, Idaho, Kansas, Maine, Mississippi, Montana, Nebraska, New Mexico, North Dakota, Utah and Wyoming.

“Everybody that we talk to is supportive of what we’re trying to do,” Partovi said. “American parents want this. Most parents are afraid that technology is passing their children by.

“When I first started this, everyone told me, ‘The system is so screwed up, you can’t fix it,’ ” Partovi said. But the response to “Hour of Code” has given him hope, he said. “I’ve got a new sense of optimism. We can do this.”

Amazon founder Jeffrey P. Bezos owns The Washington Post.