Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Bar Cohen'
- #question 1
- #input: sentence
- # letter
- #output: the number of times the letter in the sentence
- #the place of the letter in the sentence
- #the place of the letter in the words of the sentence
- def kelet_string():
- x = raw_input("please enter a sentence: ")
- while True:
- if (x == ""):
- x = raw_input("please enter a sentence: ")
- else:
- return x
- def kelet_letter():
- y = raw_input("please enter a letter: ")
- while True:
- if (y == ""):
- y = raw_input("please enter a letter: ")
- else:
- return y
- def how_many_letter(x, y):
- print "the number of " + y + " in the sentence is: "
- print x.count(y)
- def where_letter_in_string(x,y):
- print "the place of " + y + " in the sentence is: "
- import re
- print [m.start() for m in re.finditer(y, x)]
- def where_letter_in_word(x,y):
- tmp = x.split()
- for b in tmp:
- import re
- if y in b:
- print "the place of " + y + " in the word " + b + " is: "
- print [m.start() for m in re.finditer(y, b)]
- def main():
- x = kelet_string()
- y = kelet_letter()
- how_many_letter(x, y)
- where_letter_in_string(x, y)
- where_letter_in_word(x, y)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement