Предмет: Информатика, автор: kostahova2005

1)Створити функцію, яка приймає один список та повертає три максимуми зі списку. ( Наприклад список [1, 10, 4. 13. 22. 10. 0 , 105]. max_1 = 105, max_2 = 22. max_3 == 13 )
2)Створити функцію, яка приймає два списки і повертає True, якщо в першому списку парних елементів більше, ніж НЕПАРНИХ у другому.


kostahova2005: БОЖЕЧКИ…Спасибо большое за помощь

Ответы

Автор ответа: xdm2hw4hrn
1

Ответ:

Объяснение:

1) Ось розв'язки для двох функцій на Python:

Щоб знайти три максимуми зі списку, ми можемо відсортувати список за спаданням, а потім повернути перші три елементи:

def find_maxima(lst):

   sorted_lst = sorted(lst, reverse=True)

   max_1 = sorted_lst[0]

   max_2 = sorted_lst[1]

   max_3 = sorted_lst[2]

   return max_1, max_2, max_3

Щоб порівняти кількість парних і непарних елементів у двох списках, ми можемо використати вбудовану функцію суми і розуміння списку для підрахунку кількості парних і непарних елементів у кожному списку, а потім порівняти отримані результати:

def compare_lists(lst1, lst2):

   even_count_1 = sum(1 for x in lst1 if x % 2 == 0)

   odd_count_2 = sum(1 for x in lst2 if x % 2 == 1)

   return even_count_1 > odd_count_2

Ось приклад використання обох функцій:

# Example usage of find_maxima function

lst = [1, 10, 4, 13, 22, 10, 0, 105]

max_1, max_2, max_3 = find_maxima(lst)

print(max_1, max_2, max_3)  # Output: 105 22 13

# Example usage of compare_lists function

lst1 = [2, 4, 6, 8, 10]

lst2 = [1, 3, 5, 7, 9]

print(compare_lists(lst1, lst2))  # Output: True


kostahova2005: Велике дякую за допомогу.Все розписано,що та чи інша функція робить
Похожие вопросы
Предмет: Английский язык, автор: gymnazia13kmm
[05.09, 16:08] 한마디로: THE 'NO
NO IMPACT' FAMILY
Can you imagine life with no TV? What about no toilet paper?
In the Beavan family's New York apartment, there isn't a TV,
a washing machine, a dishwasher or a fridge and they're only
using one electric light bulb. In the bathroom, there aren't any
shampoo bottles, rolls of toilet paper or tubes of toothpaste.
¹_ They make them or use alternatives.
Some people think that they're crazy, but Colin Beavan explains
that it's just an experiment. 2 The Beavans are living like
this for a year because they want to reduce their impact on the
environment. At the end of the year they'll decide what they
really need and what they can live without.
They're trying to create less rubbish and use less electricity
and fuel. That's the reason why they never travel by car. ³
They buy second-hand things for the apartment and they buy
food at a market,
where they can avoid
plastic bags, packets
and boxes. They
carry the food home
in a basket, not a
plastic shopping bag.
They don't buy any
food which comes
from more than 400
kilometres away.
The Beavans also avoid takeaway food which wastes
a lot of containers. 4 In the places where Colin
has coffee, they give it to him in his jar instead of a
disposable plastic cup. They make their own yoghurt,
so they don't throw a lot of plastic pots away.
Colin says that the experiment is interesting, but it isn't
always easy. He isn't trying to change other people's
lifestyle, but he hopes that people who read his blog or
bc think about how much they use and waste.
Look at the photos and the title of the
text. Predict which of the sentences 1-6
are true or false. Then read the text and
check your answers.
The 'no impact' family...
1 live in a big city.
2use a lot of electricity.
3make their own soap.
4 are interested in the environment.
5 prefer shopping at big supermarkets.
6 prefer not to use plastic bags and
packets.пж помогите ​