I mean this politely: have you ever been assessed for ADHD? Because what you describe is textbook, and if you have it, there are meds available which work in 75% of cases.
No, not everyone can 'develop a good work ethic' and 'learn to do things they find boring'. By diagnostic definition, many people with ADHD can't. If they could, then they wouldn't have that form of ADHD.
You say anyone can do it, and then continue to say that you haven't. You are therefore blaming yourself for an inability, and making it a choice, and that, too, is normal for adult ADHD women, who live with a lot of shame which they've had ladled on all their school lives.
I was brilliant at exams. Aced them. Couldn't do coursework at all because I procrastinated, left it to the last minute, then handed mediocre work in. Exams, and I was terrified into doing intensive, hyper focused revision and excelled as a result. Nicely tight deadlines, very clear-cut. And I was able to do nothing but obsess about the exams and revision in the run-up which meant I could work harder than anyone for that short burst. Sadly, teachers assumed that hyper focused, Herculean effort was what I was capable when I tried and that if I wanted I could do it all year around - so I was labelled as lazy. I wasn't; nobody could work at that pitch all the time. I just have ADHD.
Coding - are you able to focus to the exclusion of all else, because it seems engrossing? If so, that's hyper-focus, and also common with ADHD.
Genuinely, I would explore it. If you do have it, there is effective medication. I was diagnosed as an adult and that was why I moved hell and high water to ensure my daughter was diagnosed as a child. Her meds, and mine, were life altering.