Skip to content

Commit

Permalink
Merge pull request #222 from priyankadaryani/patch-1
Browse files Browse the repository at this point in the history
Add a program to count the number of vowels in a text file.
  • Loading branch information
souravjain540 committed Aug 15, 2023
2 parents f318e40 + da10b52 commit 17cb1e8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Count_Number_of_Vowels_in_a_File.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
######## This program counts and returns the number of vowels in a text file. ########

# Ask the user for the name of the file. The file should be in the same folder and should be a text file.
print("Enter the Name of File: ")

# Convert the name to string and open the file in read mode
fileName = str(input())
fileHandle = open(fileName, "r")

# Declare a variable to store the number of vowels. Initally it is zero.
count = 0

# create an array of all the vowels (upper and lower case) that can be used to compare and determine if a character is a vowel
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']

# Read each character and compare it to the characters in the array. If found in the vowels array, then increase count.
for char in fileHandle.read():
if char in vowels:
count = count+1

# Close the file
fileHandle.close()

# Print the count to the screen for the user to see.
print("\nThe total number of vowels in the text are:")
print(count)

0 comments on commit 17cb1e8

Please sign in to comment.