A 19-year-old Kenya Certificate of Secondary Education (KCSE) candidate sat for her exams at Mama Lucy Hospital as she recuperated after delivering on Wednesday night.
The St Philip High School student said she underwent a successful Caesarean section operation and delivered a baby boy.
"I was brought here on Sunday by my mother after I went into labour. I delivered and did my exams," said Irene Wangari.
She said the exam was tough as she had to attend to her baby and that she could not yet sit upright while sitting for the exams.
However, she said the exams were fair as she had prepared well through revision.
Ms Wangari's mother said the exams were brought to the teenager in hospital on Monday but it was difficult for her as she was still lying on the bed.
She wants to be a nurse after completing her studies.
Hospital superintendent Mohammed Musa said the baby and the mother were doing well and would be discharged on Sunday.
"Getting pregnant is not the end of the world. Students should be given another chance to complete [their] education,” said Mr Musa.
He was speaking at the hospital after receiving donated non–pharmaceutical medical equipment worth over Sh10 million from Coca-Cola Africa Vice-President Susan Mboya-Kidero.
Hospital managers said that they had ensured a conducive environment for the student to sit for her exams.
County executive for health Bernard Muia said Ms Wangari situation was the first such case at the facility and that they ensured the young mother was not interrupted during the exam period.
Dr Muia said the hospital would only discharge her when she is stable.
The district education officer has urged the hospital to allow her to sit for all her exams there before discharging her, explaining that it would be a challenge to take the examination papers to her home, which is far from the school.