Question: Complete the for loop and string method needed in this function so that a function call like alpha_length(This has 1 number in it) will return

Complete the for loop and string method needed in this function so that a function call like "alpha_length("This has 1 number in it")" will return the output "17". This function should:

accept a string through the parameters of the function;

iterate over the characters in the string;

determine if each character is a letter (counting only alphabetic characters; numbers, punctuation, and spaces should be ignored);

increment the counter;

return the count of letters in the string.

def alpha_length(string):

character = ""

count_alpha = 0

# Complete the for loop sequence to iterate over "string".

for character in count_alpha:

# Complete the if-statement using a string method.

if character.isalpha():

count_alpha += 1

print(alpha_length("This has 1 number in it")) # Should print 17

print(alpha_length("Thisisallletters")) # Should print 16

print(alpha_length("This one has punctuation!")) # Should print 21

IN PYTHON PLEASE

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 Databases Questions!