Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions