Python Program - Measure Number of Letters in a Word

Published

Introduction: Python Program - Measure Number of Letters in a Word

About: Occupation: Tech Support
# Program to measure the number of letters in a word
print ("Checking to see if words in list are longer than 8 characters.")
# Open the text file and import it into the file object
alphafile = open("wordfile.txt")
# Do the following for each line in the file
for line in alphafile: 
         # Remove whitespace characters from beginning and end of line 
         # Then place the line into variable "word" 
         word = line.strip() 
         # Get the number of characters in a word 
         # And place into varible "lengthofword" 
         lengthofword = len(word)
         # Check to see of the length of the word is longer than 8 characters 
         # If it is, print out the word 
         if lengthofword > 8: 
         	print("Word longer than 8 characters:", word)

Share

    Recommendations

    • Planter Challenge

      Planter Challenge
    • Clocks Contest

      Clocks Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments