How do I ask my teacher for his honest opinion about my capabilities
As your teachers have offered to train you, it is highly unlikely that they don't believe you capable. It probably wouldn't be in either their interest or yours to continue if they thought you weren't.

Having said that, in your position, I would still seek guidance from your teacher. The way I'd go about it is to speak to your teacher face to face and say something like:

"I'd like to take the opportunity you offered to train my programming skills. Could I set up some time with you to discuss what I need to change in order to be successful this time?"

And go from there. Good luck.