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
35 lines (25 loc) · 1.03 KB
/
string_challenges.py
File metadata and controls
35 lines (25 loc) · 1.03 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
# Вывести последнюю букву в слове
word = 'Архангельск'
print(word[-1])
# Вывести количество букв "а" в слове
word = 'Архангельск'
print(word.lower().count('а'))
# Вывести количество гласных букв в слове
word = 'Архангельск'
vowels ='аеёиоуэюыя'
count = 0
for letter in word.lower():
if letter in vowels:
count += 1
print(count)
# Вывести количество слов в предложении
sentence = 'Мы приехали в гости'
print(len(sentence.split()))
# Вывести первую букву каждого слова на отдельной строке
sentence = 'Мы приехали в гости'
for word in sentence.split():
print(word[0])
# Вывести усреднённую длину слова в предложении
sentence = 'Мы приехали в гости'
sentence_1 = sentence.replace(' ', '')
print (len(sentence_1)/len(sentence.split()))