-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathstring_challenges.py
More file actions
39 lines (23 loc) · 1.08 KB
/
string_challenges.py
File metadata and controls
39 lines (23 loc) · 1.08 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
39
# Вывести последнюю букву в слове
word = 'Архангельск'
print(word[-1])
# Вывести количество букв "а" в слове
word = 'Архангельск'
print(word.lower().count('а'))
# Вывести количество гласных букв в слове
word = 'Архангельск'
vowels = ['а', 'е', 'у', 'ы', 'о', 'э', 'я', 'и', 'ю']
print(len([letter for letter in word if letter.lower() not in vowels]))
# Вывести количество слов в предложении
sentence = 'Мы приехали в гости'
print(len(sentence.split()))
# Вывести первую букву каждого слова на отдельной строке
sentence = 'Мы приехали в гости'
for word in sentence.split():
print(word[0])
# Вывести усреднённую длину слова в предложении
sentence = 'Мы приехали в гости'
words = []
for letter in sentence.split():
words.append(len(letter))
print(int(sum(words)/len(sentence.split())))