avatarMartin Andersson Aaberge

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2693

Abstract

er a good way to ask a question:</p><blockquote id="ec49"><p>“How do I calculate the area of two triangles making up a square in Python? So far I have tried the following:</p></blockquote><blockquote id="efc5"><p>The math behind the area I believe is pretty straightforward. A square has equal sides, so we know the base and the height because they’re also the same. We don’t even need to invite Pythagoras — yay! I googled the area of a triangle, and this is the formula: A = 1/2 bh. Here’s my current code:</p></blockquote><div id="9610"><pre>def find_square_area(<span class="hljs-built_in">length</span>): <span class="hljs-keyword">return</span> <span class="hljs-type">int</span>(<span class="hljs-built_in">length</span>)<span class="hljs-type">int</span>(<span class="hljs-built_in">length</span>)</pre></div><div id="d4c6"><pre>def find_triangles_area(<span class="hljs-built_in">length</span>): <span class="hljs-keyword">return</span> (<span class="hljs-number">1.2</span><span class="hljs-type">int</span>(<span class="hljs-built_in">length</span>)<span class="hljs-type">int</span>(<span class="hljs-built_in">length</span>))</pre></div><div id="1f05"><pre>side_length = input('length of square sides: ') print (<span class="hljs-name">f</span>'The area of the square is {find_square_area(<span class="hljs-name">side_length</span>)}') print (<span class="hljs-name">f</span>'The area of each triangle making up the square is {find_triangles_area(<span class="hljs-name">side_length</span>)}')</pre></div><blockquote id="9091"><p>The code seems to run, but I’m expecting half of that square area because I think that’s what it should be. I mean, I’m just slicing it in half. Am I thinking wrong or coding wrong? Appreciate the help!</p></blockquote><p id="5f96">A question of this caliber I would <i>love</i> to see more of. Clearly, the imaginary user has given it some serious thought. They have read up on the theory of the problem they want to solve and have also done the code.</p><p id="5e5f">The code seems to work, and the user is also reflecting on the logical error here. This one could easily slip, but if you stop and think, the area of each triangle can’t be bigger than the square itself. Something is clearly wrong.</p><p id="d1db">I’m sure several people would help, and we’d be able to pinpoint that the math in the <code>find_triangles_area()</code> function is incorrect. Maybe the discussion would also lead to talk about operators like <code>*=</code> — not that you need to use it, but it could spark more creativity.</p><p id="9753">For this session, we have several wins. Firstly, the original poster has learned a lot by almost figuring out th

Options

e issue. Secondly, the question is appealing to answer. This is an answer I <i>want</i> to reply to.</p><figure id="caf5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*fStqn4S3KIBE-HgB"><figcaption>Photo by <a href="https://unsplash.com/@dre0316?utm_source=medium&amp;utm_medium=referral">Andre Hunter</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h1 id="82eb">Example 2: Pythagoras</h1><p id="2959">Let’s invite Pythagoras to the party anyway and create a question related to the theory.</p><blockquote id="a104"><p>“I don’t understand The Pythagorean theorem — explain it to me.”</p></blockquote><p id="fb8f">Well, that’s a seriously vague question. Where do I even start? Considering how many sites there are online that explain this brilliantly, I don’t believe that’s the <i>real</i> question.</p><p id="3e24">If I were to answer it, maybe I’d ask something along these lines:</p><blockquote id="5d47"><p>What exactly about the Pythagorean theorem do you have trouble with? The concept, the math, or something else?</p></blockquote><p id="da0d">That should trigger some thought, and the user posting the question could go:</p><blockquote id="88bf"><p>“Well, after it’s set up, we have numbers on both sides right … 24² = 16² + b². Then, suddenly we’re doing the square root of 320 and b. Where did all the numbers go? Why are we suddenly working on 320?”</p></blockquote><p id="fee9">It turns out the user actually just has issues with the expression. Maybe they were looking at examples that skip a few steps and, therefore, made it more confusing.</p><p id="3aad">Now that we fished for more information, we can go through that piece step by step, and the user would probably get a nice reply.</p><p id="b58a">That wasn’t such a bad question though, was it? Well, if the information was there from the start, we wouldn’t have wasted a bit of time. Just a tiny snippet of information would help everyone out here.</p><h1 id="6dd6">In Conclusion</h1><p id="46d9">Whenever you want to ask a question about programming or problem-solving, make sure you have done something yourself first. If you want to actually learn from it, you have to <i>do</i> something. It’s also the best way to learn in general. You can watch all the tutorials you want, but if you never try anything out, how can you get a feel for it?</p><p id="2efa">If you want decent replies, make sure you post decent questions. You’d be surprised how many people actually enjoy helping others, myself included. I love to teach, and I love to learn. Let’s make teaching and learning great again. Thanks for reading!</p></article></body>

How to Ask Questions About Programming

You have to at least give n% of effort

Photo by bruce mars from Pexels

Programming isn’t about writing code. Programming is about problem-solving. The actual code, anyone can learn. If you are good at problem-solving, the coding part is basically learning syntax and how to search for functions, libraries, and tricks to solve the task.

Questions that don’t deserve an answer

This article is based on a series of real questions asked in various Facebook groups. The questions are legit, it’s just how you approach your audience I want to look into.

If your question is along these lines, why should anyone bother spending their personal time helping you?

“How do I solve this?” (Random screen shot of an obvious school assignment.)

“How do I do this? I have tried everything.” (Clearly didn’t try everything in the whole world.)

If you just dump out a question where you expect people to do all the work for you, you’re being disrespectful. You’re basically asking random strangers to do all the work for you while you sit back and harvest from their work.

Example 1: Area of a Triangle

“How do I calculate the area of two triangles making up a square in Python?”

Photo by Shapelined on Unsplash

The autoreply to all questions should be, “What did you try so far?” (Or, if it’s a philosophical question, “What are your thoughts on the subject so far?” Please post your current code when asking questions.

If your answer is “I haven’t tried anything yet. I just have issues solving it,” please come back when you have tried something.

The example above is a terrible way to ask that question. Here’s what I consider a good way to ask a question:

“How do I calculate the area of two triangles making up a square in Python? So far I have tried the following:

The math behind the area I believe is pretty straightforward. A square has equal sides, so we know the base and the height because they’re also the same. We don’t even need to invite Pythagoras — yay! I googled the area of a triangle, and this is the formula: A = 1/2 b*h. Here’s my current code:

def find_square_area(length):
    return int(length)*int(length)
def find_triangles_area(length):
    return (1.2*int(length)*int(length))
side_length = input('length of square sides: ')
print (f'The area of the square is {find_square_area(side_length)}')
print (f'The area of each triangle making up the square is {find_triangles_area(side_length)}')

The code seems to run, but I’m expecting half of that square area because I think that’s what it should be. I mean, I’m just slicing it in half. Am I thinking wrong or coding wrong? Appreciate the help!

A question of this caliber I would love to see more of. Clearly, the imaginary user has given it some serious thought. They have read up on the theory of the problem they want to solve and have also done the code.

The code seems to work, and the user is also reflecting on the logical error here. This one could easily slip, but if you stop and think, the area of each triangle can’t be bigger than the square itself. Something is clearly wrong.

I’m sure several people would help, and we’d be able to pinpoint that the math in the find_triangles_area() function is incorrect. Maybe the discussion would also lead to talk about operators like *= — not that you need to use it, but it could spark more creativity.

For this session, we have several wins. Firstly, the original poster has learned a lot by almost figuring out the issue. Secondly, the question is appealing to answer. This is an answer I want to reply to.

Photo by Andre Hunter on Unsplash

Example 2: Pythagoras

Let’s invite Pythagoras to the party anyway and create a question related to the theory.

“I don’t understand The Pythagorean theorem — explain it to me.”

Well, that’s a seriously vague question. Where do I even start? Considering how many sites there are online that explain this brilliantly, I don’t believe that’s the real question.

If I were to answer it, maybe I’d ask something along these lines:

What exactly about the Pythagorean theorem do you have trouble with? The concept, the math, or something else?

That should trigger some thought, and the user posting the question could go:

“Well, after it’s set up, we have numbers on both sides right … 24² = 16² + b². Then, suddenly we’re doing the square root of 320 and b. Where did all the numbers go? Why are we suddenly working on 320?”

It turns out the user actually just has issues with the expression. Maybe they were looking at examples that skip a few steps and, therefore, made it more confusing.

Now that we fished for more information, we can go through that piece step by step, and the user would probably get a nice reply.

That wasn’t such a bad question though, was it? Well, if the information was there from the start, we wouldn’t have wasted a bit of time. Just a tiny snippet of information would help everyone out here.

In Conclusion

Whenever you want to ask a question about programming or problem-solving, make sure you have done something yourself first. If you want to actually learn from it, you have to do something. It’s also the best way to learn in general. You can watch all the tutorials you want, but if you never try anything out, how can you get a feel for it?

If you want decent replies, make sure you post decent questions. You’d be surprised how many people actually enjoy helping others, myself included. I love to teach, and I love to learn. Let’s make teaching and learning great again. Thanks for reading!

Software Engineering
Programming
Data Science
Python3
Python
Recommended from ReadMedium