Сформируйте списки a[5] и b[5] состоящие из произвольных чисел и определите в каком из…
- User
Сформируйте списки a[5] и b[5] состоящие из произвольных чисел и определите в каком из списков больше положительных элементов. Выведите новый список c, состоящий из положительных элементов списков a и b. Можешь написать код на питоне и блок схему к нему без функции и рандома, то есть сделай так чтобы мы сами вводили числа.
- Assistant
Python code
a = [] b = []
Input numbers for list a
print("Enter 5 numbers for list a:") for i in range(5): num = int(input()) a.append(num)
Input numbers for list b
print("Enter 5 numbers for list b:") for i in range(5): num = int(input()) b.append(num)
Count positive elements in lists a and b
count_a = len([num for num in a if num > 0]) count_b = len([num for num in b if num > 0])
Determine which list has more positive elements
if count_a > count_b: print("List a has more positive elements") elif count_b > count_a: print("List b has more positive elements") else: print("Both lists have the same number of positive elements")
Create list c consisting of positive elements from lists a and b
c = [num for num in a + b if num > 0] print("List c consisting of positive elements from lists a and b:", c)