Check the number of letters in a sentence
sentence = input("Enter a sentence: ")
letters_count = 0 for char in sentence: if char.isalpha(): letters_count += 1 print("Number of letters:", letters_count) This program prompts the user to enter a sentence. It then iterates over each character in the sentence. If a character is an alphabetic letter (using the `isalpha()` method), it increments the `letters_count` variable. Finally, it prints the total number of letters in the sentence.
Comments
Post a Comment