Stack Overflow is a community; it has a history and rules (both formally established and unspoken). Entering a new community is always a bit tricky. Mistakes are going to happen, and sometimes it's hard to tell exactly where the misstep occurred. The most important thing is that we learn and move forward with shared experience.
I would like to give an answerers perspective to provide some insight into why I might choose to answer or not answer a question.
This is the initial version of the question:
How can I check if a string contains only English characters, exclamation marks at the end?
For example "hello!!" should return true, whereas "45!!","!!ok" should return false. The only case where it should return true is when string has English characters (a-z) with 0 or more exclamation marks in the end.
python string
This is a difficult question to answer. There are many reasons for why answering this question could cause issues.
This initial post seems like what could be referred to as a "low effort question".
As has been seen the question garnered a generally negative response, this response can often extend to answers. Not that reputation is the end-all be-all of why people choose to answer questions, but others often avoid putting themselves in a situation where they can be downvoted by association.
Often new users are directed to How much research effort is expected of Stack Overflow users? which outlines quite a few points, but the one in particular that I'd like to draw attention to is this answer which quotes text that was previously in the official How do I ask a good question? guidelines
"Tell us what you found and why it didn’t meet your needs."
It is true that this guidance is no longer listed, but that does not mean that the community has stopped expecting this (which admittedly can be confusing to someone new). However, sharing what was tried can really provide a lot of context about the level of understanding the user has:
- What kinds of things have you searched for?
- What was close to working but didn't?
- What didn't work at all and why?
Answers to these questions can point to exactly where the problem is and exclude all of the things that have already been attempted. We don't want to make more work for everyone
From the tour "This site is all about getting answers. It's not a discussion forum. There's no chit-chat." Extended conversation in the comments is not permitted.
The largest amount of space to provide information is the Question and Answer spaces. The comments are quite limited and a back-and-forth like:
"Have you tried `x`?"
"Yes that didn't work because `y`."
"Well what about `z`?"
"No `z` doesn't work because `q`."
does not fit into the structure of Stack Overflow well. This may also apply to an answer. I have had quite a few experiences wherein I proposed a solution and I received a comment like: "Oh sorry, I forgot to mention I can't use x
because y
." This means that I spent time making an answer that does not solve the current problem. Typically an edit is made to the question which invalidates my answer (by adding a requirement that was not present in the initial). Now if I have the following options:
- update my question to account for the new requirement (which can involve entirely refactoring my answer)
- delete my answer and move on (which can be frustrating to both answerer and asker)
- continue a back-and-forth trying to figure out what other things were missing from the requirement (but by consequence generating a lot of "noise" in the comments)
- rollback the edit and let them know that it's generally not reasonable to edit the question after receiving answers in such a way that completely changes the requirements and invalidates existing answers (which is often leads to another source of conflict)
Depending on how I'm feeling I may choose to just avoid all of this by not answering the question if it's border-line, and/or vote to close until the question meets the minimum requirements.
A better structured question could have been something like:
How can I check if a string contains only English characters, exclamation marks at the end?
I am trying to test whether a string contains only English letters (a-z) with any number of exclamation points at the end. For example, "hello!!" should return True
, but "45!!" or "!!ok" should return False
. "45!!" should be False
because of the numbers even though it ends with exclamation points. "!!ok" should be False
because it does not end with exclamation points at the end and there are exclamation points at the beginning which is not allowed.
In my research so far, I came across How can I check if a string only contains letters in Python? which recommends string.isalpha()
as show in this answer, but this does not work because it will only check for alphabetical characters and won't help determine if it ends with an exclamation point or not. There's an answer which uses a module re
, but I'm not familiar enough to know whether or not I can modify this to fit my purposes.
This is my best attempt so far:
def fun(s):
i = -1
for i in range(0, len(s)):
if s[i] == '!':
break
elif 'a' <= s[i] <= 'z':
continue
else:
return 0
while i < len(s):
if s[i] != '!':
return 0
i += 1
return 1
print(fun("hello!!"))
python string
[Code snippet modified from Revision 2 of the question How can I check if a string contains only English characters, exclamation marks at the end? by laser]
I do not know for certain that this version of the question would have been better received. However, this is the question of someone who (in my mind) understands exactly what they're looking for, and has put in thought and time into solving it themselves.
Now let's address some of the other questions:
Are other questions actually well received or are they just old?
But I wonder why a question like this one gets so many upvotes even though it's similar to my question at the time when I posed it (i.e., without code).
This question How can I check if a string only contains letters in Python? is 8 years old with 170k views. It has a net score of 62 (+64 -2). Meaning (roughly) 0.036% of people who came across this question chose to upvote it. Questions that have been around for many years are not necessarily a good indication of how questions will or will not be received today. It is yet unknown if in 2029 this question will also have 60+ upvotes.
Assumptions about user knowledge
Why does Stack Overflow assume that a user has knowledge of every domain (and where that domain is applicable)?
There may be some users who have unreasonable expectations of the knowledge of an asker, but on the whole the expectation is that you share what you do know. We cannot determine if you are unaware of a technology or specifically avoiding it for some reason. The line added to revision 3 is super helpful because it lets us know that you're open to any and all possible solutions:
Following is my solution using iterative method, however I want to know some clean method having fewer lines of code (maybe by using some python library).
It also provides a clear direction for answers. This is a question about solving this specific problem in a more understandable and straightforward way.
Assumptions about Homework Questions
I think it's impossible to know if any user has posted his/her homework irrespective of how much prior work that person has done and any sort of help for homework would be unfair and thus Stack Overflow should stop suspecting because it's impossible to prove it person is asking a homework question.
It does not matter whether or not a question is Homework or not. "The Homework Question" is a type of question wherein someone dumps a problem onto the site without any effort and expects someone to provide them a complete solution. It's this type of behaviour that we try to discourage and has specific guidelines in the faq How do I ask and answer homework questions?. While this question may not be a homework question the first version is also certainly not not a homework question. Providing the things mentioned above and in the top rated answer of the faq we're just looking for some evidence of effort and clear guidelines for how to help.
Some final words: do not be discouraged. The current version of the question is fairly reasonable. It seems like this was an instance where a reasonable question was asked and a reasonable amount of effort was done to solve the problem, but those things just didn't get translated into the question itself.
I would also like to link to the Stack Overflow question checklist which can be very helpful to provide an exact framework to test whether or not the question has all of the components necessary.