Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 14 - Tuples, Sets, and Dictionaries - Programming Exercises - Page 497: 14.11

Answer

code

Work Step by Step

# 14.11 (Count consonants and vowels) Write a program that prompts the user to enter a # text filename and displays the number of vowels and consonants in the file. Use # a set to store the vowels A, E, I, O, and U. vowels = {'a', 'e', 'i', 'o', 'u'} count_vowels = 0 count_consonants = 0 file = open(input("Enter filename: ")) lines = file.readlines() for line in lines: for word in line.split(): for c in word.lower(): if c in vowels: count_vowels += 1 else: count_consonants += 1 print("Total number of vowels =", count_vowels) print("Total number of consonants =", count_consonants)
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.