My current code works but not how i want it to work. Currently if i enter a word i.e. "compc" and then search for the character "c" the output will be:
'c' found at index 0
Sorry, no occurrences of 'c' found at index 1
Sorry, no occurrences of 'c' found at index 2
Sorry, no occurrences of 'c' found at index 3
'c' found at index 4
but what i want it to do is only show:
'c' found at index 0
'c' found at index 4
If no characters were found then simply:
Sorry, no occurrences of 'c' found
My current code is:
print("This program finds all indexes of a character in a string. \n")
inStr = input("Enter a string to search:\n")
searchChar = input("\nWhat character to find? ")
searchChar = searchChar[0]
anyFound = False
startAt = 0
index = startAt
while index < len(inStr):
if inStr[index] == searchChar:
anyFound = True
if anyFound == True:
print ("'" + searchChar + "' found at index", index)
index = index + 1
anyFound = False
else:
anyFound == False
print("Sorry, no occurrences of '" + searchChar + "' found")
index = index + 1