Answer the question
In order to leave comments, you need to log in
How to enter an array in Python like in c++??
switched from c++;
it's easier there
for (i=0;i<n;++)
for (j=0;j<m;++)
cin>>a[i][j];
n=int(input())
m=int(input())
num = [[int(input()) for i in range(n)] for j in range(m)]
for i in range(0,n):
print("\n")
for j in range(0,m):
print(num[i][j], end=' ')
IndexError: list index out of range
print(num[i][j], end=' ')
Answer the question
In order to leave comments, you need to log in
Swap n/m in cycles.
Better yet, iterate over the array itself.
import random
n=int(input())
m=int(input())
num = [[int(random.randint(1,6)) for i in range(n)] for j in range(m)]
for i in num:
print("\n")
for j in i:
print(j, end=' ')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question