Ejercicio: 3Eva2002TI_T1 Triunfos, empates y derrotas por Goles
Instrucciones en Python
explicación en video:
Algoritmo en Python
# 3Eva_IT2002_T1 Triunfos, empates y derrotas por Goles
import numpy as np
# INGRESO
goles = np.array([[0,4,2,1],
[5,0,3,2],
[0,2,0,1],
[1,0,2,0]])
# PROCEDIMIENTO
tamano = np.shape(goles)
n = tamano[0]
m = tamano[1]
triunfos = np.zeros(shape=(n,m),dtype=int)
ttriunfos = np.zeros(n,dtype=int)
# calcular los triunfos
i = 0
while not(i>=n):
j = 0
while not(j>=m):
if (goles[i,j] > goles[j,i]):
triunfos[i,j] = 1
triunfos[j,i] = 0
j = j + 1
i = i + 1
# calcular total de triunfos
i = 0
while not(i>=n):
j = 0
while not(j>=m):
ttriunfos[i] = ttriunfos[i] + triunfos[i,j]
j = j + 1
i = i + 1
# calcular empates
empates = np.zeros(shape=(n,m),dtype=int)
tempates = np.zeros(n,dtype=int)
i = 0
while not(i>=n):
j = 0
while not(j>=m):
if (goles[i,j] == goles[j,i]) and (i!=j):
empates[i,j] = 1
empates[j,i] = 1
j = j + 1
i = i + 1
# calcular total de empates
i = 0
while not(i>=n):
j = 0
while not(j>=m):
tempates[i] = tempates[i] + empates[i,j]
j = j + 1
i = i + 1
# Derrotas
derrotas = (n-1)*np.ones(n,dtype=int)
derrotas = derrotas - ttriunfos - tempates
# SALIDA
print(triunfos)
print(' triunfos por equipo: ')
print(ttriunfos)
print(empates)
print(' empates por equipo:')
print(tempates)
print(' derrotas por equipo:')
print(derrotas)