Commit 70b19bff authored by AnDKulakova's avatar AnDKulakova
Browse files

Update,, text.txt files

import string
class Text:
#Открываем текст и считываем
def __init__(self, text):
self.text = open(f'{text}', 'r')
self.r =
#Нахождение слова с максимальной длиной
def maxdlina(self):
self.max = max(self.r, key=len)
print(f'Самое длинное слово в тексте - {self.max}')
#Нахождение слова с минимальной длиной
def mindlina(self):
self.min = min(self.r, key=len)
print(f'Самое короткое слово в тексте - {self.min}')
#Ищем наиболее часто встречающийся символ
def chasto_vstrech_simv(self):
count = 0
n = self.r[0]
for i in self.r:
chastot = self.r.count(i)
if chastot > count:
count = chastot
n = i
print(f'Слово, которое встречается чаще всего - {n}')
#Считаем количество слов, начинающихся на символ, заданный пользовотелем
def kol_slov(self, bukva):
self.bukva = bukva
words = []
for i in self.r:
words += [j for j in i.split() if j.startswith(self.bukva)]
k = len(words)
print(f'Количество слов, которые начинаются на {self.bukva}: {k}')
#Подсчитываем процент отношения символов , . ? ! к общему количеству символов
def procent_simvol(self):
simvols = [',', '.', '?', '!']
k = 0
for i in self.r:
for j in list(i):
if j in simvols:
k += 1
k = k / len(self.r) * 100
print(f"Символы ',', '.', '?', '!' составляют {round(k, 2)}% процентов по отношению к общему количеству символов в тексте")
#Закрываем текст
def stop(self):
from function import Text
if __name__ == '__main__':
a = Text('text.txt')
letter = input('Введите букву, чтобы посчитать сколько слов в тексте начинается на эту букву:')
I would I were a careless child,
Still dwelling in my highland cave,
Or roaming through the dusky wild,
Or bounding o'er the dark blue wave;
The cumbrous pomp of Saxon pride
Accords not with the freeborn soul,
Which loves the mountain's craggy side,
And seeks the rocks where billows roll.
Fortune! take back these cultured lands,
Take back this name of splendid sound!
I hate the touch of servile hands,
I hate the slaves that cringe around.
Place me among the rocks I love,
Which sound to Ocean's wildest roar;
I ask but this � again to rove
Through scenes my youth hath known before.
Few are my years, and yet I feel
The world was ne'er designed for me:
Ah! why do dark'ning shades conceal
The hour when man must cease to be?
Once I beheld a splendid dream,
A visionary scene of bliss:
Truth! � wherefore did thy hated beam
Awake me to a world like this?
I loved - but those I loved are gone;
Had friends � my early friends are fled:
How cheerless feels the heart alone
When all its former hopes are dead!
Though gay companions o'er the bowl
Dispel awhile the sense of ill;
Though pleasure stirs the maddening soul,
The heart � the heart � is lonely still.
How dull! to hear the voice of those
Whom rank or chance, whom wealth or power,
Have made, though neither friends nor foes,
Associates of the festive hour.
Give me again a faithful few,
In years and feelings still the same,
And I will fly the midnight crew,
Where boist'rous joy is but a name.
And woman, lovely woman! thou,
My hope, my comforter, my all!
How cold must be my bosom now,
When e'en thy smiles begin to pall!
Without a sigh I would resign
This busy scene of splendid woe,
To make that calm contentment mine,
Which virtue knows, or seems to know.
Fain would I fly the haunts of men �
I seek to shun, not hate mankind;
My breast requires the sullen glen,
Whose gloom may suit a darken'd mind.
Oh! that to me the wings were given
Which bear the turtle to her nest!
Then would I cleave the vault of heaven,
To flee away and be at rest.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment