Good evening guys, I have this array:
Ineedtheaddedarraynumberstoall15
.Bothverticallyandhorizontally.
Code:
importnumpyasnpimportrandomfromtabulateimporttabulatea=[1,2,3,4,5,6,7,8,9]random.shuffle(a)data=np.reshape(a,(3,3))soma_horizontal=[]forlistaindata:soma_horizontal.append(sum(lista))soma_vertical=[]forxinrange(len(data)):soma=0forlistaindata:soma+=lista[x]soma_vertical.append(soma)indice=0forlistaindata:lista.extend(['\u2192',soma_horizontal[indice]])indice+=1setas_cima=['\u2191']*3data=[soma_vertical]+[setas_cima]+dataprint(tabulate(data,tablefmt="grid", stralign='center', numalign='center'))
The program running on repl: