• Предмет: Информатика
  • Автор: pawlomakarcuk
  • Вопрос задан 3 месяца назад

Дано дві групи чисел: 6, 2, 13, і 5, 8, 16, 9. Розробіть програму створення з цих чисел двох множин, об’єднання їх у одну множину, визначення довжини нової множини, обчислення загальної суми чисел множини та визначення в ній наявності числа 15.​


hagadf: мова програмування?
pawlomakarcuk: Пайтон

Ответы

Ответ дал: hagadf
1

Код:

# Define the two sets of numbers

set1 = {6, 2, 13}

set2 = {5, 8, 16, 9}

# Combine the sets into a single set

new_set = set1.union(set2)

# Find the length of the new set

length = len(new_set)

print("Length of the new set:", length)

# Find the sum of the numbers in the new set

total_sum = sum(new_set)

print("Sum of the numbers in the new set:", total_sum)

# Check if the number 15 is in the new set

if 15 in new_set:

   print("15 is in the new set.")

else:

   print("15 is not in the new set.")

Виведення в консолі:

Length of the new set: 7

Sum of the numbers in the new set: 55

15 is not in the new set.

Можна найкращу відповідь)


pawlomakarcuk: дякую вам
pawlomakarcuk: допоможіть ще будь ласка
pawlomakarcuk: даю 100 балів
Вас заинтересует