Learning how to ask a good question is an acquired skill.
First of all, you should realize that most people don't start out asking perfectly-framed questions. Many people ask badly-scoped questions, forget necessary context and sometimes don't really get across what they want to know. This is normal. Falling down is part of learning how to walk.
In the spirit of helping people improve their questions, I'll share my personal experience with what I consider particularly good about questions.
A question needs a clear answer
Nothing is more frustrating than reading through a question three times and still not understanding what OP actually wants to know. In order to avoid this, I usually put a clearly defined question both in the title and on the bottom of my question.
Provide relevant context
Sometimes questions turn out to be an XY-problem, so it's always good to explain why you are asking something, and why you did the things that you did. Of course, if your problem is "Why does this code result in this exception?", then usually it's irrelevant to mention what the program you are writing is supposed to do.
In that example, however, it's vital to include a Minimal, Verifiable, Complete Example. As the name suggests, this example code should be as small as possible, clearly demonstrate the problem in question and be ready to be copy/pasted and run.
Being able to tell what context is relevant and what context isn't is a skill that needs honing over time, but it's a good thing for a student to be at least aware of.
Make sure the question is in-scope of the site
I'm usually on Information Security, where one of the rules is that questions aiming to break the security of a specific system, without demonstrating a deep understanding of the techniques involved and identifying a specific problem, are off-topic. Simply put: We are not hackers for hire.
Other sites have similar rules, so it's best to join the relevant meta for that site and ask if a specific question is on-topic or not. Usually, the people there will either say yes, or they will point out alternate ways to get to that information.
Use Markdown formatting (correctly)!
A question without any kind of formatting, even if it is just basic linebreaks, will not get any answer from me. Try this by editing my answer and removing all formatting. It looks unreadable, even though the information has not changed.
Likewise, excesive formatting actually hinders readability
and only creates
work for the editors who have to remove the
Expect some barrier to entry
This is very important advice. While the community at large tries its best to be as welcoming as possible, sometimes actions are misunderstood or interpreted as hostility. Putting a question on hold, editing it, asking for clarification, etc...
All of these actions aim to aid Stack Exchange as a whole, and are not meant as an attack to the person. If your new question is downvoted, stick around and ask how to improve it. As I said above, it's a vital part of learning.
You can also ask on the relevant meta-sites or the chat room of that site if there are problems with that question.
As a foot-note, I would like to mention that showing effort in asking better questions is a very good thing. Putting in the time and effort to ask better questions will inevitably result in people wanting to put in the time and effort to answer questions.