Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: vowel_count.py
- # Author: Jeoi Reqi
- """
- Vowel Count Script
- This script reads text from a specified file in the same directory and counts
- the number of vowels in the text. It utilizes a function, count_vowels, to
- perform the vowel counting operation.
- Requirements:
- - Python 3
- Usage:
- 1. Save the text file in the same directory as the script.
- 2. Replace 'texty.txt' with the actual file name in the script.
- 3. Run the script.
- 4. The script will display the number of vowels in the text.
- """
- def count_vowels(text):
- """Count the number of vowels in a text.
- Args:
- text (str): Text.
- Returns:
- int: Number of vowels in the text.
- """
- vowels = ['a', 'e', 'i', 'o', 'u']
- return sum(text.lower().count(vowel) for vowel in vowels)
- def read_text_from_file(file_path):
- """Read text from a file.
- Args:
- file_path (str): Path to the file.
- Returns:
- str: Text read from the file.
- """
- with open(file_path, 'r', encoding='utf-8') as file:
- return file.read()
- def main():
- # Specify the file path
- file_path = 'texty.txt' # Replace 'texty.txt' with the actual file name
- # Read text from the file
- text = read_text_from_file(file_path)
- # Count vowels
- vowel_count = count_vowels(text)
- # Display the result
- print(f"Number of vowels in the text: {vowel_count}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement