Image copyright Getty Images Image caption A non-exam programming task was worth a fifth of the marks in computer science GCSE

GCSE computer science programming tasks worth a fifth of the marks will no longer count towards students' final grades after they were leaked online.

Writing to students, exams regulator Ofqual said the decision had been made "with reluctance" but "we do not want anyone to have an unfair advantage".

Repeated leaks of the questions and answers emerged in November, throwing the qualification into disarray.

Students should still complete the tasks as planned, the letter said.

"While not contributing to your grade, the task will continue to be an important part of the qualification," said Ofqual's director for general qualifications, Julie Swan, in the letter.

"Learning about a high-level programming language and having the opportunity to show that you can use it to solve problems is an important aspect of a computer science course of study."

The change affects students due to sit the exam in 2018 and 2019.

'Dismay and disappointment'

More than 2,500 people, mainly students and teachers, responded to an Ofqual consultation on how to proceed, which was launched after it became clear that students who had completed the task, and possibly some teachers, had posted details to online forums and collaborative programming sites, contrary to exam board rules.

In the letter, Ms Swan assured students that Ofqual had read all their responses.

"It is clear that many of you have strong views about the current situation," she said.

"We know that not everyone will agree with our decision.

"However, if we do not act now, it would be impossible for us to correct any unfairness caused by rules being broken."

Geoff Barton, general secretary of the Association of School and College Leaders, which represents secondary heads, said the decision would be greeted "by a huge sense of dismay and disappointment" in schools.

"Finding out half way through the year that their hard work will no longer count towards their final grade is a particular source of disappointment for students," said Mr Barton.

"They will feel as if they have had the rug pulled from under their feet."

But he acknowledged that Ofqual had to act to ensure fairness once evidence of irregularity had emerged.

"They cannot stand on the sidelines," he said.

Ofqual said it expected teachers to set aside lesson time for students to complete the programming tasks and exam boards would be responsible for monitoring schools to ensure this happened.

The changes affect all exam boards offering computer science GCSE.

About 70,000 students were entered for the subject last year.