+ 1
Getting certain amount of symbols from string in Python.
Please help with following task. Need to return 2 symbols from middle of the word if it have even symbols and 3 if there is odd number of symbols. Example: #even Input: bottle Output: tt #odd Input: bottles Output: ttl
6 ответов
+ 2
You are really supposed to give it a try and post your attempt, before asking others to solve it for you.
https://code.sololearn.com/cMudPEWx14Xq/?ref=app
+ 2
What if the string length was 3 or 1? These are both odd, but for the case of 3, it means the whole string is returned. And if it is only 1 character length, then there's not enough characters to return 3 characters.
+ 2
Thanks everybody. Especially Jayakrishna, however output of the code is differ from what I trying to solve.
What I need is when input abcdef
Output should be: cd
And when I input: abcdefg
Output: cde
However thanks for your attention and time.
+ 2
Tibor Santa thank you very much for solution from now I post my attempts as well. Thanks for advice.
+ 1
In=input()
i=len(In)
if(i%2==1) :
print(In[i//2-1])
print(In[i//2]+In[i//2+1])
0
What you tried to get it?