Untitled
unknown
python
2 years ago
1.4 kB
4
Indexable
string_01 = "History is always written by the winners. hen two cultures clash, the loser is obliterated, and the winner writes the history books-books which glorify their own cause and disparage the conquered foe. As Napoleon once said, 'What is history, but a fable agreed upon?" without_spaces = len(string_01.replace(' ', '')) #удалили все пробелы и посчитали длину строки без пробелов string_01 = string_01.replace('-', ' ') #заменили в строке знак "-" на пробел words = len(string_01.split()) #разбили строку на список со словами, посчитали длину списка print('Количество символов, исключая пробелы:', without_spaces) print('Количество слов в строке:', words) letter = input() #ввели букву string_01 = string_01.lower().replace("'", '') #привели все буквы к нижнему регистру и убрали символ ' sp = string_01.split() #разбили строку на список слов q = 0 for i in sp: if i[0] == letter: #если первая буква слова соответсвует введенйо букве q+=1 print(f'Слова на букву {letter} встречаются в тексте {q} раз')
Editor is loading...