Предмет: Информатика,
автор: pawlomakarcuk
Дано дві групи чисел: 6, 2, 13, і 5, 8, 16, 9. Розробіть програму створення з цих чисел двох множин, об’єднання їх у одну множину, визначення довжини нової множини, обчислення загальної суми чисел множини та визначення в ній наявності числа 15.
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.
Можна найкращу відповідь)
Похожие вопросы
Предмет: Математика,
автор: krivoruckosofia931
Предмет: Математика,
автор: navisasa09
Предмет: Английский язык,
автор: aminanuradzieva
Предмет: Литература,
автор: Fomina1970mariya
Предмет: Русский язык,
автор: SlavaF10128