Guest User

Untitled

a guest
Oct 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. word = input("Enter a string: ")
  2. length = len(word)
  3.  
  4. is_f_found = False
  5.  
  6. # find the first f
  7. for i in range(length):
  8. if word[i] == "f":
  9. print(i) # the first f is found, print its location
  10. is_f_found = True
  11. break
  12.  
  13.  
  14. # find the last f
  15. for j in range(length-1, i, -1):
  16. if word[j] == "f":
  17. print(j) # the first f is found, print its location
  18. is_f_found = True
  19. break
  20.  
  21. if not(is_f_found):
  22. print(-1)
Add Comment
Please, Sign In to add comment