помогите пожалуйста пайтон 3.11.2
Ответы
Код Python:
Реализация с random:
import random
pos_nums = []
neg_nums = []
even_nums = []
square_even_nums = []
odd_nums = []
nums_list = []
for x in range(60):
nums_list.append(random.randint(-1000, 1000))
for num in nums_list:
if num > 0:
pos_nums.append(num)
elif num < 0:
neg_nums.append(num)
if num % 2 == 0:
even_nums.append(num)
else:
odd_nums.append(num)
for x in even_nums:
square_even_nums.append(x ** 2)
print(pos_nums, len(pos_nums))
print(neg_nums)
print(even_nums, square_even_nums)
print(odd_nums)
Реализация с вводом (вводим числа в одну строку через пробел):
pos_nums = []
neg_nums = []
even_nums = []
square_even_nums = []
odd_nums = []
nums_list = input().split()
for num in nums_list:
num = int(num)
if num > 0:
pos_nums.append(num)
elif num < 0:
neg_nums.append(num)
if num % 2 == 0:
even_nums.append(num)
else:
odd_nums.append(num)
for x in even_nums:
square_even_nums.append(x ** 2)
print(pos_nums, len(pos_nums))
print(neg_nums)
print(even_nums, square_even_nums)
print(odd_nums)