Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Ask GOOD Questions

People always say there is no such thing as a bad question, but when it comes to programming, it is possible to ask a question badly. When you’re asking for help from someone who has little or no context on the problem you are trying to solve, then it’s best to ask GOOD questions by following this acronym:

  • G: Give context on what you are trying to do, clearly describing the problem.
  • O: Outline the things you have already tried to fix the issue.
  • O: Offer your best guess as to what the problem might be. This helps the person who is helping you to not only know what you are thinking, but also know that you have done some thinking on your own.
  • D: Demo what is happening. Include the code, a traceback error message, and an explanation of the steps you executed that resulted in the error. This way, the person helping does not have to try to recreate the issue.

Good questions can save a lot of time. Skipping any of these steps can result in back-and-forth conversations that can cause conflict. As a beginner, you want to make sure you ask good questions so that you practice communicating your thought process, and so that people who help you will be happy to continue helping you.

00:01 Ask “Good” Questions.

00:05 At many points in your programming career, you’re going to need to ask for help, and often that can come in the form of asking questions on sites such as Stack Overflow. When doing so, it’s really important that you ask questions in the right way so people can help you without duplicating the kind of testing that you’ve already done, and that you can give them a good idea of what you’ve already done and what you’re intending the program to do. Firstly, the G of GOOD: Give context on what you’re trying to do, clearly describing the problem. So here on the left, we can see a bad example—it just says, “Can’t print properly”—whereas on the right, we’ve got a good example: “I’m trying to use an f-string with formatting combined with a variable to give 6 total digits and 1 decimal place, but I can’t find the right syntax.”

00:53 The one on the left could be anything from printing on a printer to using the print statement, whereas the one on the right is really clear—we know exactly where we are and what the problem is.

01:05 O: Outline the things you’ve already tried to fix the issue. Again, you see this quite often: “Tried everything,” on the left. That’s not really helpful. It’s unlikely you’ve actually tried every possibility. On the right, you can see what the user has tried—the different variations, including an old-style .format(), but nothing has worked for them.

01:29 Next, offering the best guess as to what the problem might be. This helps the person who’s helping you not only to know what you’re thinking, but also to know that you’ve done some thinking on your own.

01:38 You’ve not just fallen at the first hurdle and thrown the problem out for someone else to do. Again, on the left we have a bad example: “No idea what’s wrong.” And on the right: “I can make the formatting work using old-style formatting, but I can’t see where to insert the variable in the new style.” This is clear and concise and will hopefully point anyone who’s trying to answer the question in the right direction, to find somebody who knows really well how to use f-strings.

02:06 D stands for Demo. So, demo what’s happening—include the code, traceback error message, or an explanation of the steps you’ve executed that resulted in the error.

02:14 This way, the person helping does not have to try to recreate the issue. So, including all of the code that’s relevant is really important, and you see this quite often where people can’t help because they don’t want to spend half an hour trying to work out what somebody’s done.

02:28 They want to just be able to copy the code, try running it themselves—or maybe just by looking at the code, they’ll be able to tell the person what’s wrong. So, here on the left, the bad example: no code at all. On the right, a good example: the variable’s been set, they’re using old style formatting, and it says # this works, but it's not an f-string.

02:48 That should yield a good answer fairly quickly.

02:53 Quite often, when you put all the information together to ask the question to someone else, the answer will become apparent to you because you’ve put all that information in a way you haven’t seen before, and new ideas can come to you as a result of that.

03:07 You may realize there’s something you haven’t tried, or there may be something that you didn’t try in the right way.

Avatar image for avinashhm

avinashhm on Aug. 15, 2019

I love this video lesson .. its very valuable to any newbies in a community to learn how to describe a problem better making it faster, more likely to get a good response.

Avatar image for tuxis2

tuxis2 on Jan. 29, 2020

In the ask good questions video it seems like it’s being asked about #an old way of doing.
string = "A number of words"
float_number = 9000.0
print(f'I can insert "{string}{float_number}" things into the brackets')
Old way?..: Using the Syntax : {}.format(value) or if there are multiple: {} {}.format(value1, value2)
string = "A number of words"
float_number = 9000.0
print('I can also insert "{} {}" things into the brackets this old way'.format(string, float_number))
So it seems the answer with the new method is:
var = 372.52
print(f"{var:06.1f}")
But I’m not sure if it’s correct nor do I quite understand it, what is :06.1f ?
Avatar image for tuxis2

tuxis2 on Jan. 29, 2020

Should have used “Toggle Preview” to make it more legible, since it seems I can’t edit it directly.

This part is more legible this way.

Using the Syntax : {}.format(value)

Syntax if there are multiple: {} {}.format(value1, value2)

Avatar image for tuxis2

tuxis2 on Jan. 29, 2020

Answerish:

print(f"12.3:06.1f}")

12.3- Is just a number.

:- I’m not sure what to call the colon but it seems to do something under the hood to get it to work.

0- Indicates what symbol to use to “pad” the left side.

6- Gives us the number of symbols that must be printed.

.- The period before 1f is also needed to get it to work.

1f- Signifies that it should be displayed as floating point number with 1 decimal place.

Since 12.3 already has four symbols, the number of 0’s we need to pad the left side with to reach 6 symbols in total is 2 or “00”

print(f"12.3:06.1f}")

Will therefore print: 0012.3

Why would you use this?

One use case is if you have many numbers and you want them all to line up underneath each other with the . in the right place.

0012.3

0912.3

9999.9

Simpler one if you just want to use space.

print(f"{12.3:<15} Wow, how did I end up moving 15spaces this way?")
# or
print(f"{12.3:>15}")

It’s kind of the opposite of what I would expect because I feel like it should point towards the side the spaces are being made but it is actually pointing towards the side the number will stay “stuck” to.

”<” The number is justified left.

”>” The number is justified right.

Become a Member to join the conversation.