Skip to content

Conversation

@nazar0810
Copy link

No description provided.

Comment on lines +5 to +10

list1 = list(input('список='))
k = 0
if isinstance(list1[k], str):
k += 1
print(k) 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.

оскільки список дано, то використання функціїї введення користувачем input() не є коректним. Поставлену задачу краще виконати так:
list1 = [65, True, 67.87, 'cola', 'pepsi', 34, 'what']
str_count = 0
for element in list1:
if isinstance(element, str):
str_count+=1

print('Кількість елементів списку типу string: ', str_count)

Comment on lines +6 to +9
import string
text1 = list(input('Введіть текст:'))
text2 = text1
print(text2) 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.

Програма не виконує поставлене завдання. Виконання завдання слід реалізувати так:

Tim Dorotyuk, [24.12.19 01:23]
text1 = input('Введіть текст:')
text_list = text1.split()
res_list = []
for element in text_list:
res_list.append(element.capitalize())
result_string = ' '.join(res_list)
print(result_string)

Comment on lines +6 to +12
text1 = str(input('text:'))
list1 = ','.join(list(text1))
n = 0
if isinstance(list1[n], int):
list1.remove(str)
n += 1
print (list1) 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.

list_text = [32434.332, 'dssd', 32234, '3234']
len_of_list = len(list_text)
for element in list_text:
if type(element) == int:
list_text.remove(element)
print(list_text)

Comment on lines +5 to +19
import re
def validator ():
text = input('Введіть дані:')
if bool(re.compile('^(Begin){1}\\n writeln{0,+}readln{0,+}(Begin){0,1} writeln{0,+}readln{0,+} end{0,1}\\n end{1}$',text)):
print ('Yes')
else:
print ('no')
validator()

flag = input('для запуску програми натисніть \"Enter\", щою завершити програми \"n\"')
if flag != 'n':
validator()
flag = input('для запуску програми натисніть \"Enter\", щою завершити програми \"n\"')
else:
print('Допобачення') 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.

Для того, аби програма нормально працювала, слід переписати регулярний вираз, а такжо замінити compile на match. Після цих змін програма має виглядати наступним чином:

import re
def validator ():
text = input('Введіть дані:')
if bool(re.match('[(Begin){1,2}(writeln())+(end){1,2}]',text)):
print ('Yes')
else:
print ('no')
validator()

flag = input('для запуску програми натисніть "Enter", щою завершити програми "n"')
if flag != 'n':
validator()
flag = input('для запуску програми натисніть "Enter", щою завершити програми "n"')
else:
print('Допобачення')

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