Answer the question
In order to leave comments, you need to log in
4. Given a matrix D(4,4) of real numbers. How to replace all elements below the main diagonal with zeros?
wrote the code for this task, but the teacher said that this task can be completed without the if condition, immediately in those cycles that set the matrix. How to do it?
import random
n=4
a=[]
for i in range (n):
b=[]
for j in range (n):
if i>j:
b.append(0)
else:
b.append(random.randint(-100,100))
a.append(b)
for i in a:
for m in i:
print(m, end=' ')
print()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question