daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Oct 19th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top