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 ___:

# Complete the if-statement using a string method.

if ___:

count_alpha += 1

return count_alpha

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Well complete the alphalength function to count only the alphabetic characters in a given string The ... View full answer

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!