Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to ent

ID: 3873477 • Letter: U

Question

USING PYTHON PROGRAMING LANGUAGE

Write a program that first asks the user to enter a “special” letter. The program should then ask the user to enter a single line sentence containing all lowercase letters and no punctuation, except for a period at the end. The program will then output the number of times that this letter appears in the sentence.

Example:

Enter a special letter: t
Enter a sentence: here is my little sentence.
Your letter appears 3 times.
(t and here is my little sentence. are user inputs, the rest is output by the program.)

Explanation / Answer

Python 2.7 code:

print "Enter a special letter: "
letter = raw_input().strip(); #take input the special letter
print "Enter a sentence: "
sentence = raw_input().strip(); #take input the sentence
count = 0 #counter for occurence of letter
for c in sentence:
if(c == letter):
  count = count + 1
print "Your letter appears ", count, " times."

Sample Output:

Enter a special letter:
t
Enter a sentence:
here is my little sentence.
Your letter appears 3 times.