import random;
matriz =[[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "]]
def print_matriz():
print("---------");
aux = str("");
i = 0;
while(i < len(matriz)):
j = 0;
while(j < len(matriz)):
aux = aux + str(matriz[i][j]) + "\t";
j = j + 1;
i = i + 1;
print(aux);
aux = "";
print("---------");
def numbers():
print("you have to choose the minimun and maximum for filling up a square");
aux2 = False;
while(aux2 == False):
aux = False;
aux1 = False;
while(aux == False):
min = input("which number do you want to be the minimum? ");
try:
int(min);
min = int(min);
aux = True;
except:
print("a number please");
while(aux1 == False):
max = input("which number do you want to be the maximum? ");
try:
int(max);
max = int(max);
aux1 = True;
except:
print("a number please");
if(max - min < 0):
print("maximum must be bigger than minimum");
aux2 = False;
else:
aux2 = True;
place_numbers(min,max);
print_matriz();
addition_recursive(0,0);
biggest_recursive(auxialiary,0,1,0);
print("the row/s with biggest addition is/are: ")
print_result(0);
def place_numbers(min,max):
i = 0;
while(i < len(matriz)):
j = 0;
while(j < len(matriz)):
matriz[i][j] = random.randint(min,max);
j = j + 1;
i = i + 1;
auxialiary = [0,0,0,0,0];
def addition_recursive(i,j):
global auxialiary;
if(i == len(matriz)):
return
else:
if(i == 0):
auxialiary[0] = auxialiary[0] + matriz[i][j];
elif(i == 1):
auxialiary[1] = auxialiary[1] + matriz[i][j];
elif(i == 2):
auxialiary[2] = auxialiary[2] + matriz[i][j];
elif(i == 3):
auxialiary[3] = auxialiary[3] + matriz[i][j];
elif(i == 4):
auxialiary[4] = auxialiary[4] + matriz[i][j];
if(j == 4):
addition_recursive(i + 1, 0);
else:
addition_recursive(i, j + 1)
auxialiary1 = ["","","","",""];
def biggest_recursive(array, position, comparable, counter):
global auxialiary1;
if(position + comparable == len(array)):
return;
if(array[position] < array[position + comparable]):
auxialiary1 = ["","","","",""];
auxialiary1[0] = str(position + comparable);
biggest_recursive(array, position + comparable, 1, 1);
elif(array[position] > array[position + comparable]):
auxialiary1 = ["","","","",""];
auxialiary1[0] = str(position);
biggest_recursive(array, position, comparable + 1, 1);
else:
if(counter == 0):
auxialiary1[0] = str(position);
counter = counter + 1
auxialiary1[counter] = str(position + comparable);
biggest_recursive(array, position, comparable + 1, counter + 1);
def print_result(position):
if(position == len(auxialiary1)):
return;
if(str.isdigit(auxialiary1[position]) == True):
print(int(auxialiary1[position]) + 1);
print_result(position + 1);
print_matriz();
numbers();