During his speech, Obama told pupils that as well as teachers, parents and the government, they were responsible for their own success at school.
"No matter what you want to do with your life - I guarantee you'll need an education to do it," he said.
"Your goal can be something as simple as doing all your homework, paying attention in class, or spending time each day reading a book."
'Not easy'
But he also warned that being successful was hard, and used Harry Potter author JK Rowling as an example of someone who'd had to overcome failures before finding success.