xxxxxxxxxx
OUTPUT :
Enter the limit of the array = 2
Enter the values of first array =
a1[0][0] = 1
a1[0][1] = 2
a1[1][0] = 3
a1[1][1] = 4
Enter the values of second array =
a2[0][0] = 5
a2[0][1] = 6
a2[1][0] = 7
a2[1][1] = 8
First array =
1 2
3 4
Second array =
5 6
7 8
Sum =
6 8
10 12
CODE :
n = int(input("Enter the limit of the array = "))
print("Enter the values of first array = ")
a1 = []
for i in range(n):
t = []
for j in range(n):
m = int(input(f"a1[{i}][{j}] = "))
t.append(m)
a1.append(t)
print("Enter the values of second array = ")
a2 = []
for i in range(n):
t = []
for j in range(n):
m = int(input(f"a2[{i}][{j}] = "))
t.append(m)
a2.append(t)
a3 = []
for i in range(n):
t = []
for j in range(n):
m = a1[i][j]+a2[i][j]
t.append(m)
a3.append(t)
print("First array = ")
for i in range(n):
for j in range(n):
print(a1[i][j],end=" ")
print()
print("Second array = ")
for i in range(n):
for j in range(n):
print(a2[i][j],end=" ")
print()
print("Sum = ")
for i in range(n):
for j in range(n):
print(a3[i][j],end=" ")
print()
xxxxxxxxxx
temp_list = [[], [], [], []]
temp_list[0].append("a1")
temp_list[1].append("a2")
temp_list[2].append("a3")
temp_list[3].append("a4")
xxxxxxxxxx
n,m=int(input()),int(input())
for i in range(0,n):
for j in range(0,m):
a[i].append(int(input()))
xxxxxxxxxx
#create 2D array Matrix 4X4
Matrix = [[0 for i in range(4)] for j in range(4)]
#2D array python
x=[[11, 12,13],[14, 15,16],[17, 18,19]]
sum(sum(x,[]))
xxxxxxxxxx
"""0 shows no error , 1 shows error"""
error_list=[] #main error list
p=0 #p - phone field
e=1 #e - mail field
d=1 #d - date field
temp_error=[] #temporary error list created and to collect data everytime
if(p==1):
temp_error.append('invalid number')
if(e==1):
temp_error.append('invalid email')
if(d==1):
temp_error.append('invalid admit date')
error_list.append(temp_error)
#second call (you can call it recursively too by calling function name)
p=1 #p - phone field
e=0 #e - mail field
d=1 #d - date field
temp_error=[]
if(p==1):
temp_error.append('invalid number')
if(e==1):
temp_error.append('invalid email')
if(d==1):
temp_error.append('invalid admit date')
error_list.append(temp_error)
print(error_list)
#OUTPUT : [['invalid email','invalid admit date'],['invalid number','invalid admit date']]