3.4.10 AverageWordLength sample answer.py - #First let's start with letter count There are a few ways#we could implement letter count but because we

3.4.10 AverageWordLength sample answer.py - #First let's...

This preview shows page 1 out of 1 page.

#----------------------------------------------------------- #First, let's start with letter count. There are a few ways #we could implement letter count, but because we know our #string is only spaces and letters, we can do this an easy #way. # #First, we create the function: def letter_count(a_string): #Then, start the counter: letters = 0 #Then, we loop through each letter in the function: for character in a_string: #If it's not a space, then it must be a letter! if not character == " ": letters += 1 #Finally, we return how many letters we found. return letters #word_count is the exact opposite. Instead of counting the #characters that are not spaces, we only want to count the
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Fall '19
  • susan lee

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes