-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathstring_challenges.py
More file actions
51 lines (39 loc) · 1.28 KB
/
string_challenges.py
File metadata and controls
51 lines (39 loc) · 1.28 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
40
41
42
43
44
45
46
47
48
49
50
51
# Вывести последнюю букву в слове
word = 'Архангельск'
last = word[-1]
print(last)
# ???
# Вывести количество букв "а" в слове
word = 'Архангельск'
a= word.lower()
print(a.count('а'))
# ???
# Вывести количество гласных букв в слове
word = 'Архангельск'
vowels = "аеёиоуыэюяАЕЁОИУЫЭЮЯ"
count_vow = 0
for letter in word.lower():
if letter in vowels:
count_vow += 1
print(count_vow)
# ???
# Вывести количество слов в предложении
sentence = 'Мы приехали в гости'
words = sentence.split()
num_words = len(words)
print(num_words)
# ???
# Вывести первую букву каждого слова на отдельной строке
sentence = 'Мы приехали в гости'
words = sentence.split()
for word in words:
print(word[0])
# ???
# Вывести усреднённую длину слова в предложении
sentence = 'Мы приехали в гости'
words = sentence.split()
num_words = len(words)
for word in words:
avg_word_len = len(sentence) / num_words
print(f"Средняя длина слова в предложении {avg_word_len}")
# ???