Skip to content

Conversation

@Rostislav3
Copy link

No description provided.


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)

#Вивести усі порожні списки з поданого списку


L= [ 1, 2, [], 21, 22, [],1223, [], 'hi']

Choose a reason for hiding this comment

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

Краще назвати змінну list, не записувати назву змінної в одну букву

Choose a reason for hiding this comment

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

L= [ 1, 2, [], 21, 22, [],1223, [], 'hi']
def count_empt_list(L):
   return L.count([])

print(count_empt_list(L))

Comment on lines +3 to +7
text=input("Введіть рядок\n")
words=text.split(" ")
for word in words:
if(word[0].isupper()):
print(word) No newline at end of file

Choose a reason for hiding this comment

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

Можливо краще створити порожній список і додавати в нього елементи, які знаходяться у верхньому регістрі: result = []
string = input('Введіть рядок: ')
string= string.split(' ')

for i in string:
for j in i:
if(j.isupper()):
result.append(i)
break
print(result)

Choose a reason for hiding this comment

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

string = input()
def uppercase_letters(string):
    result = []
    for el in string.split():
        if any(elem.isupper() for elem in el):
            result.append(el)
    return result
print(uppercase_letters(string))

elif (type(L[i])) == str:
string = string + L[i] + ''
else:
print("Не працює\n",L[i])

Choose a reason for hiding this comment

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

  1. Навіщо потрібен 12 рядок коду, у завданні незазначений цей пункт.
  2. Напевно краще виконати це завдання застосувавши функцію isinstance, вона створена спеціально для перевірки приналежності даних конкретному типу даних:
L = [1 ,22,35,76,'hi',[],22,'Bro']
sum = 0
string = ""
for value in L:
    if isinstance(value, int):
        sum = sum + value
    elif isinstance(value, str):
        string = string + ' ' + value
print("Сума чисел -",sum)
print("Об'єднання рядків -",string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants