Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_characters(file_path):
- with open(file_path, 'r') as file:
- text = file.read()
- char_count = len(text)
- line_count = text.count('\n')
- vowel_count = sum(1 for char in text if char.lower() in 'aeiouаеёиоуыэюя')
- consonant_count = sum(1 for char in text if char.isalpha() and char.lower() not in 'aeiouаеёиоуыэюя')
- digit_count = sum(1 for char in text if char.isdigit())
- return char_count, line_count, vowel_count, consonant_count, digit_count
- def write_statistics(file_path, statistics):
- with open(file_path, 'w') as file:
- file.write("Статистика по исходному файлу:\n")
- file.write(f"Количество символов: {statistics[0]}\n")
- file.write(f"Количество строк: {statistics[1]}\n")
- file.write(f"Количество гласных букв: {statistics[2]}\n")
- file.write(f"Количество согласных букв: {statistics[3]}\n")
- file.write(f"Количество цифр: {statistics[4]}\n")
- # Пример использования
- input_file_path = 'input.txt' # Путь к исходному файлу
- output_file_path = 'statistics.txt' # Путь к файлу со статистикой
- statistics = count_characters(input_file_path)
- write_statistics(output_file_path, statistics)
- print("Статистика успешно записана в файл.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement