Get a string value(set of characters) and then get a value from the user where you can start to print the string from the index-based, then create a middle value from the string, after that check whether the value is greater or lesser, Check the value is greater than 0, you can initialise the middle value, used this formula(middle=int(len(string)/2)), print the string from based on value index number, for example first get a string “Python”, then get value is 1 after actual output is “h”.

Sample Program:

string=input("Enter the string:")
value=int(input("Enter the value for where you can start and end up:"))
if value>0:
    middle=int(len(string)/2)
if value>middle:
    print(string[middle:len(string)])
else:
    print(string[middle:middle+value])

Sample Input:

Enter the string:Python
Enter the value for where you can start and end up:1

Actual output:

h

Any queries leave a comment please and thanks for reading this post.

Leave a Reply

Your email address will not be published. Required fields are marked *