MPs have thanked David Cameron for his six years of service in his last Prime Minister's Questions before he stands down later on Wednesday.

In often light-hearted exchanges, Cameron revealed he believes he has answered around 5500 questions at the despatch box, but joked he would leave it to others to decide how many he has answered.

Leader of the Opposition Jeremy Corbyn pressed Cameron on questions over homelessness and the status of EU nationals, but also jokingly asked if Cameron intended to take over from Len Goodman as the head judge on Strictly Come Dancing.

The SNP's leader at Westminster Angus Robertson struck a more serious note, telling Cameron his benches "won't be applauding his premiership" and blaming the outgoing Prime Minister for Brexit.

At the end of the session, Conservative MPs gave Cameron a standing ovation and Labour MPs applauded, while SNP MPs chose to do neither.

The Conservative benches were joined on their feet by Liberal Democrat former deputy prime minister Nick Clegg and a number of Labour politicians.

Cameron said he "done a bit of research" on his time as Prime Minister, adding: "I've addressed 5500 questions from this despatch box - I'll leave it to others to work out how many I've answered."

Addressing Speaker of the House John Bercow, he said: "Because of your belief in letting everyone have their say, I think I've done a record of 92 hours of statements from this despatch box as well as some very enjoyable Liaison Committee appearances and other things."

Opening his remarks, Labour leader Jeremy Corbyn thanked the Prime Minister for his service and praised him for his role in the release of Shaker Aamer from Guantanamo Bay and in the introduction of equal marriage legislation.

He raised issues surrounding homelessness, the rights of EU nationals living in the UK and the economy, warning that homelessness has risen for the past six years and looks set to continue rising.

Cameron responded that homelessness figures were "10% below the peak we saw under Labour" but added that "we need to quicken the pace" with regards to housing.

On equal marriage the Prime Minister said: "I will never forget the day at No 10 when one of the people who works very close to the front door said to me 'I'm not that interested in politics, Mr Cameron, but because of something your lot has done I'm able to marry the person I've loved all my life this weekend'.

"There are many amazing moments in this job but that actually was one of my favourites."

He also reserved a few pot-shots for the Labour leader, saying of Theresa May's imminent succession to the office of Prime Minister: "When it comes to woman prime ministers, pretty soon I am pleased to say it is going to be two-nil - and not a pink bus in sight."

He was referring to a pink bus Labour had launched to target women voters in 2015.

Corbyn insisted there would be "plenty more to come" from him for Theresa May after telling MPs he has asked Mr Cameron 179 questions.

Before his 180th question, Corbyn wished Cameron and his family well, adding: "I'd also like you to pass on my thanks to your mum for her advice about ties and suits and songs.

"It's extremely kind of her and I'd be grateful if you could pass that on to her personally. I'm reflecting on the lesson she offered."

This referred to an earlier exchange during which Cameron offered the Labour leader what he imagined his mother's advice would be: to "put on a proper suit, do up your tie and sing the national anthem".

Corbyn also joked: "There's a rumour going around that your departure has been carefully choreographed so you can slip seamlessly into the vacancy created this morning on Strictly by Len Goodman's departure.

"Is that your next career?"

The SNP benches altered the tone of the exchanges, with Westminster leader Angus Robertson telling Cameron he had brought the UK to the "brink of being taken out of the European Union".

While wishing Cameron and his family well, Robertson said: "However, the Prime Minister's legacy will undoubtedly be that he has taken us to the brink of being taken out of the European Union so we will not be applauding his premiership on these benches.

"What advice has he given his successor on taking Scotland out of the EU against the wishes of Scottish voters?"

Robertson said Cameron's successor Theresa May is "very well known" in Scotland because of the planned deportation of the Brain family from the Highlands.

He also pointed to the likelihood that May's first major Commons vote would be on "imposing" Trident against the wishes of "almost every single MP from Scotland".

"How does the outgoing prime minister think that all of this will go down in Scotland?" he asked.

Cameron replied it was right that MPs will vote on Trident and that "many people in Scotland support our nuclear deterrent".

He said: "You ask about the record of this Government when it comes to Scotland, well I'll tell him what it is: 143,000 more people in work in Scotland, massive investment in the renewable industries in Scotland, the two biggest warships ever built in our history built in Scotland, a powerhouse parliament, a referendum that was legal, decisive and fair, and I might add a Scotsman winning Wimbledon twice while I was prime minister."