mat1 = <ваш двумерный массив>
for i in len(mat):
for j in len(mat[i]):
if mat[i][j] == 5:
print(i, j)
mat2 = [[4, -5, 10], [9, 0, 8], [-30, 15, 11]]
countmn = 0
countb0 = 0
for i in sum(mat2, []):
if i < 0:
countmn += 1 #тоже самое что и countmn = countmn + 1
if i > 0:
countb0 += 1
print('Количество отрицательных чисел:', countmn)
print('Количество положительных чисел:', countb0)
for i in mat:
for j in i:
if j % 2:
print(j)
count_positive_number = 0
count_negative_number = 0
if mat[i][j] > 0:
count_positive_number += 1
mat[i][j] **= 2 #mat[i][j] = mat[i][j] ** 2
elif mat[i][j] < 0:
count_negative_number += 1
if count_positive_number == count_negative_number:
print('Равны')
elif count_positive_number > count_negative_number:
print('Положительные числа')
else:
print('Отрицательные числа')
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
mat1 = <ваш двумерный массив>
for i in len(mat):
for j in len(mat[i]):
if mat[i][j] == 5:
print(i, j)
mat2 = [[4, -5, 10], [9, 0, 8], [-30, 15, 11]]
countmn = 0
countb0 = 0
for i in sum(mat2, []):
if i < 0:
countmn += 1 #тоже самое что и countmn = countmn + 1
if i > 0:
countb0 += 1
print('Количество отрицательных чисел:', countmn)
print('Количество положительных чисел:', countb0)
for i in mat:
for j in i:
if j % 2:
print(j)
count_positive_number = 0
count_negative_number = 0
for i in len(mat):
for j in len(mat[i]):
if mat[i][j] > 0:
count_positive_number += 1
mat[i][j] **= 2 #mat[i][j] = mat[i][j] ** 2
elif mat[i][j] < 0:
count_negative_number += 1
if count_positive_number == count_negative_number:
print('Равны')
elif count_positive_number > count_negative_number:
print('Положительные числа')
else:
print('Отрицательные числа')