Question: def count _ letters ( text ) : # Initialize a new dictionary. dictionary = _ _ _ # Complete the for loop to iterate

def count_letters(text):
# Initialize a new dictionary.
dictionary =___
# Complete the for loop to iterate through each "text" character and
# use a string method to ensure all letters are lowercase.
for ___
# Complete the if-statement using a string method to check if the
# character is a letter.
if___
# Complete the if-statement using a logical operator to check if
# the letter is not already in the dictionary.
if ___
# Use a dictionary operation to add the letter as a key
# and set the initial count value to zero.
___
# Use a dictionary operation to increment the letter count value
# for the existing key.
___
___ # Increment the letter counter.
return dictionary
print(count_letters("AaBbCc"))
# Should be {'a': 2,'b': 2,'c': 2}
print(count_letters("Math is fun! 2+2=4"))
# Should be {'m': 1,'a': 1,'t': 1,'h': 1,'i': 1,'s': 1,'f': 1,'u': 1,'n': 1}
print(count_letters("This is a sentence."))
# Should be {'t': 2,'h': 1,'i': 2,'s': 3,'a': 1,'e': 3,'n': 2,'c': 1}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!