Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dorotiuktv/first/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Недоречно імпортувати цілу бібліотеку, краще замінити на from re import match

'''
Створити регулярний вираз, що буде перевіряти, чи правильно записана конструкція besin-writeln()-end. У цій послідовності
слід дотримуватися наступних правил: всередині begin може розташовуватись максимум ще одна кострукція, що починається з
begin. Очевидно, що кількість слів end має бути аналогічною. При цьому кількість вкладень writeln() не обмежуэться. Весь
вираз записується без використання пробільних символів
'''

def res_func(str_1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для кращої читабельності коду функції варто назвати validator

"""checking the input string"""
if bool(re.match('^[begin ]{1,2}[writeln() ]+[end]{1,2}$', str_1)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Регулярний вираз не коректний для даної задачі, потрібно замінити на (^(begin begin)(( begin)( readln()| writeln())( begin){0,1}( end){0,1}( readln()| writeln())( end))*$)

print('YES')
else:
print('NO')
Comment on lines +12 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Краще повертати змінну типу bool , для підвищення універсальності функції.



in_string = input('Введіть рядок: ')

res_func(in_string)
8 changes: 8 additions & 0 deletions dorotiuktv/second/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'''
Дано список, що включає в себе елементи різних типів. визначити кількість пустих вкладених списків, що містяться у цьому
початковому списку.
'''

list_1 = ['jdsf', 'jkldsf', 174268, 325, True, [], '12', []]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Варто список назвати main_list


print(list_1.count([]))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нагромаджування виклику функцій . Для підвищення читабільності варто розбити на кілька змінних .

11 changes: 11 additions & 0 deletions dorotiuktv/second/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Дано довільний рядок, що є реченням. Вивести кожне 3 слово в цьому реченні.
"""

text_1 = 'Найбілишим містом України і одночасно столицею країни є Київ'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Назву text_1 варто замінити на line для більшї читабельності коду

list_sentence = text_1.split()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не зовсім зрозуміла назва list_sentence, краще замінити на list_word

if len(list_sentence) < 3:
print('Введене вами речення містить менше 3 слів')
else:
for word in list_sentence[::3]:
print(word)
10 changes: 10 additions & 0 deletions dorotiuktv/second/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'''
Користувач вводить 2 цілих числа. Вивести на екран усі числа, що містяться між визначиними числами(тобто, не включаючи
їх).
'''

num_1 = int(input('Пепрше число: '))
num_2 = int(input('Друге число: '))
Comment on lines +6 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Немає перевірки на тип данних, які вводяться з клавіатури, що може призвести до помилки ValueError


for number in range(num_1+1, num_2):
print(number)