Answer to Question #256448 in Python for rasi

Question #256448

17. Write a code for returning a character at the specified index.


1
Expert's answer
2021-10-30T00:40:49-0400


SOLUTION FOR THE ABOVE QUESTION>


SAMPLE PROGRAM OUTPUT



SOLUTION CODE FRO THE QUESTION


#prompt the user to enter a string
my_string = input("\nEnter a string: ")
#Find the length of the string
string_length = len(my_string)

#Propmt the user to enter the index of the character to access
index = int(input("\nEnter the index of the character you want to access: "))

#Check if index is less than the string length
if(index < string_length and (index > 0 or index == 0)):
    print("\nThe character at index "+str(index)+" is "+my_string[index])
else:
    print("\nYou have entered invalid index, please try again")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS