Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- word = input("Enter a string: ")
- length = len(word)
- is_f_found = False
- # find the first f
- for i in range(length):
- if word[i] == "f":
- print(i) # the first f is found, print its location
- is_f_found = True
- break
- # find the last f
- for j in range(length-1, i, -1):
- if word[j] == "f":
- print(j) # the first f is found, print its location
- is_f_found = True
- break
- if not(is_f_found):
- print(-1)
Add Comment
Please, Sign In to add comment