пожалуйста помогите, очень нужно. python
Ответы
1)
import random
number_list = []
for n in range(10):
number_list.append(random.randint(-10, 10))
print(number_list)
number_list = [number * -1 for number in number_list]
print(number_list)
2)
import random
number_list = []
for n in range(10):
number_list.append(random.randint(-10, 10))
amount = 0
for number in number_list:
amount += number
print(amount)
3)
import random
number_list = []
for i in range(10):
number_list.append(random.randint(-10, 10))
number_list = [number ** 2 for number in number_list]
amount = 0
for n in number_list:
amount += n
print(amount)
4)
import random
number_list = []
for n in range(10):
number_list.append(random.randint(-10, 10))
negative_numbers = []
positive_numbers = []
for number in number_list:
if number < 0:
negative_numbers.append(number)
elif number > 0:
positive_numbers.append(number)
amount_positive = 0
amount_negative = 0
for n in negative_numbers:
amount_negative += n
print('сумма отрицательных чисел: ' + str(amount_negative))
for p in positive_numbers:
amount_positive += p
print('сумма положительных: ' + str(amount_positive))