Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. 'Bar Cohen'
  2. #question 1
  3. #input: sentence
  4. # letter
  5. #output: the number of times the letter in the sentence
  6. #the place of the letter in the sentence
  7. #the place of the letter in the words of the sentence
  8.  
  9. def kelet_string():
  10. x = raw_input("please enter a sentence: ")
  11. while True:
  12. if (x == ""):
  13. x = raw_input("please enter a sentence: ")
  14. else:
  15. return x
  16.  
  17. def kelet_letter():
  18. y = raw_input("please enter a letter: ")
  19. while True:
  20. if (y == ""):
  21. y = raw_input("please enter a letter: ")
  22. else:
  23. return y
  24.  
  25. def how_many_letter(x, y):
  26. print "the number of " + y + " in the sentence is: "
  27. print x.count(y)
  28.  
  29. def where_letter_in_string(x,y):
  30. print "the place of " + y + " in the sentence is: "
  31. import re
  32. print [m.start() for m in re.finditer(y, x)]
  33.  
  34. def where_letter_in_word(x,y):
  35. tmp = x.split()
  36. for b in tmp:
  37. import re
  38. if y in b:
  39. print "the place of " + y + " in the word " + b + " is: "
  40. print [m.start() for m in re.finditer(y, b)]
  41.  
  42. def main():
  43. x = kelet_string()
  44. y = kelet_letter()
  45. how_many_letter(x, y)
  46. where_letter_in_string(x, y)
  47. where_letter_in_word(x, y)
  48. if __name__ == '__main__':
  49. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement