Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions malininrp/first/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Вивести усі порожні списки з поданого списку


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))

print("Порожніх списків:\n", L.count( []))
7 changes: 7 additions & 0 deletions malininrp/first/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Вивести усі слова котрі містять в слові велику букву

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

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))

14 changes: 14 additions & 0 deletions malininrp/first/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Порахувати суму САМЕ чисел в списку

L=[1 ,22,35,76,'hi',[],22,'Bro']
sum=0
string=''
for i in range(len(L)):
if (type(L[i])) == int:
sum=sum +L[i]
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)

print("Сума чисел\n",sum)
print("Об'єднання рядків\n",string)