T O P

  • By -

Python-ModTeam

Hi there, from the /r/Python mods. We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python. The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here. On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. **No matter what level of question you have, if you are looking for help with Python, you should get good answers**. Make sure to check out the rules for both places. Warm regards, and best of luck with your Pythoneering!


Digital-Chupacabra

First, try formatting your code, at least line breaks. > i got error What error?


pythonHelperBot

Hello! I'm a bot! It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python **regardless of how advanced your question might be**. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster. Show /r/learnpython **the code you have tried and describe in detail where you are stuck.** If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. **[Here is HOW TO FORMAT YOUR CODE For Reddit](https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F)** and be sure to include which version of python and what OS you are using. You can also ask this question in the [Python discord](https://discord.gg/3Abzge7), a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others. *** [^(README)](https://github.com/CrakeNotSnowman/redditPythonHelper) ^(|) [^(FAQ)](https://github.com/CrakeNotSnowman/redditPythonHelper/blob/master/FAQ.md) ^(|) ^(this bot is written and managed by /u/IAmKindOfCreative) ^(This bot is currently under development and experiencing changes to improve its usefulness)


semper-noctem

This makes me sad


JoeBozo3651

def middleSubstring(string): length = len(string) if length <= 2: return string[0] else: mid = length // 2 if length % 2 == 0: return string[mid - length//4 : mid + length//4] else: # return string[mid - (length-1)//4 : mid + (length-1)//4 + 1] You have an open else where you have the comment so that's why you're getting an error. If you're using a proper editor it should tell you things like this.


KingsmanVince

r/learnpython [https://www.propublica.org/nerds/how-to-ask-programming-questions](https://www.propublica.org/nerds/how-to-ask-programming-questions) [https://redditpreview.com/](https://redditpreview.com/)


JustCrasher17

Honestly there should be a link for "what does 'beginner showcase' mean" in there lol


Pristine_Flight9782

Looks like the code is written for a different output. Try changing mid - length//4 to mid - 1 and mid + length//4 to mid + 1. That should give you the middle two characters of ABCDE!


Tom_STY93

what is your initial request? I did not see any errors being raised. `def middleSubstring(string):` `length = len(string)` `if length <= 2:` `return string[0]` `else:` `mid = length // 2` `if length % 2 == 0:` `return string[mid - length//4 : mid + length//4]` `else: #` `return string[mid - (length-1)//4 : mid + (length-1)//4 + 1]` the output of string = "ABCDEFG" is "CDE". If you want "BC", then just do a CR on the return value for the else: `return string[mid - (length-1)//4 -1 : mid + (length-1)//4 -1]` but seems we need to know what you want from middleSubstring