forked from learnpythonru/basic_exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_challenges.py
More file actions
38 lines (28 loc) · 1.06 KB
/
string_challenges.py
File metadata and controls
38 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Вывести последнюю букву в слове
word = 'Архангельск'
print(word[-1])
# Вывести количество букв "а" в слове
word = 'Архангельск'
print(word.lower().count('а'))
# Вывести количество гласных букв в слове
word = 'Архангельск'
count = 0
for i in word.lower():
if i in 'ауоыяюёие':
count += 1
print(count)
# Вывести количество слов в предложении
sentence = 'Мы приехали в гости'
print(len(sentence.split()))
# Вывести первую букву каждого слова на отдельной строке
sentence = 'Мы приехали в гости'
for i in sentence.split():
print(i[0])
# Вывести усреднённую длину слова в предложении
sentence = 'Мы приехали в гости'
count_word = len(sentence.split())
count_letter = 0
for i in sentence:
if i.isalpha():
count_letter += 1
print(count_letter / count_word)