Skip to content
Open
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions malininrp/second/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#"Використовуючи регулярні вирази, для поданого нижче тексту замініть кожне входження автомобільного номеру у форматі `АА 0000 BB` на текст `[номер АА]`. Виведіть результат."

import re

numb = str(input('Введіть номер автомобіля\n'))

Choose a reason for hiding this comment

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

нема сенсу писати str(input()), бо input() і так повертає str

Choose a reason for hiding this comment

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

Регулярний вираз виглядає не дуже,навіщо тут потрібен метод split.
Програма не працює. Це завдання можно виконати наступним чином:

import re


text = input("Введіть текст з форматом номера [АА 0000 BB]\n")

find = re.findall("[A-Z]{2}\s\d{4}\s[A-Z]{2}", text)

for i in find:
    replace = i[3:8] + i[:2]
    text = re.sub("[A-Z]{2}\s\d{4}\s[A-Z]{2}", replace, text)

print(text)

numb2 = re.split('\w\d\d\d\d\w',numb)
print(numb2)