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
Step: 1
Well complete the alphalength function to count only the alphabetic characters in a given string The ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started