Hello all,
Newbie Pythoner here.
I have been tasked with Counting Letters in a Sentence. However, I cannot use the Count function. What I have to do is the following:
1) Write a program that asks the user to input a sentence.
2) The program will ask the user what two letters are to be counted.
3) You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence.
My code is below. As you can see, I used the count function to obtain an understanding of how the function works. My code is still non-functioning.
Anyways, can anyone provide a little guidance of how I can find how to letters can be counted using a For loop and not using the counting function?
Newbie Pythoner here.
I have been tasked with Counting Letters in a Sentence. However, I cannot use the Count function. What I have to do is the following:
1) Write a program that asks the user to input a sentence.
2) The program will ask the user what two letters are to be counted.
3) You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence.
My code is below. As you can see, I used the count function to obtain an understanding of how the function works. My code is still non-functioning.
Anyways, can anyone provide a little guidance of how I can find how to letters can be counted using a For loop and not using the counting function?
sentence = "Hello World" lettersToFind = 'L', 'E' count = 0 for INDEX in range (0, len(sentence), 1): if sentence[INDEX] == lettersToFind: count = count + 1 print("The", lettersToFind,"were found at index:", INDEX) print(lettersToFind, "was found", count, "times")