-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconteo_jugadores.py
More file actions
59 lines (51 loc) · 2.85 KB
/
conteo_jugadores.py
File metadata and controls
59 lines (51 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# clasificacion_jugadores.py
#from carga_jugadores import jugadores
# Carga inicial de los jugadores desde el archivo
jugadores = []
def contar_velocidad():
velocidad_L = len([p for p in jugadores if p['velocidad'] == 'L'])
velocidad_M = len([p for p in jugadores if p['velocidad'] == 'M'])
velocidad_R = len([p for p in jugadores if p['velocidad'] == 'R'])
return velocidad_L, velocidad_M, velocidad_R
def posicion_cancha():
posicion_cancha_1 = len([p for p in jugadores if p['posicion_cancha'] == 'arquero'] )
posicion_cancha_2 = len([p for p in jugadores if p['posicion_cancha'] == 'defensor'] )
posicion_cancha_3= len([p for p in jugadores if p['posicion_cancha'] == 'central'] )
posicion_cancha_7= len([p for p in jugadores if p['posicion_cancha'] == 'saguero'] )
posicion_cancha_5= len([p for p in jugadores if p['posicion_cancha'] == 'mediocampo'] )
posicion_cancha_9 = len([p for p in jugadores if p['posicion_cancha'] == 'delantero'] )
posicion_cancha_10= len([p for p in jugadores if p['posicion_cancha'] == 'armador'] )
return posicion_cancha_1, posicion_cancha_2, posicion_cancha_3 , posicion_cancha_7, posicion_cancha_5 , posicion_cancha_9 ,posicion_cancha_10
def contar_por_nivel():
nivel_regular = len([p for p in jugadores if p['nivel_jugador'] == 'REGULAR'])
nivel_medio = len([p for p in jugadores if p['nivel_jugador'] == 'MEDIO'])
nivel_bueno = len([p for p in jugadores if p['nivel_jugador'] == 'BUENO'])
return nivel_regular, nivel_medio, nivel_bueno
def guardar_jugadores(jugadores, archivo="jugadores.txt"):
with open(archivo, "a") as file:
for jugador in jugadores:
# Convierte el diccionario a una línea de texto
linea = f"{jugador['nombre_apellido']},{jugador['velocidad']},{jugador['posicion_cancha']},{jugador['nivel_jugador']},{jugador['edad']}\n"
file.write(linea)
print(f"Jugadores guardados en {archivo}")
# Función para cargar jugadores desde un archivo .txt
def cargar_jugadores(archivo="jugadores.txt"):
global jugadores
jugadores_txt = []
jugadores = jugadores_txt
try:
with open(archivo, "r") as file:
for linea in file:
nombre_apellido, velocidad, posicion_cancha, nivel_jugador, edad = linea.strip().split(",")
jugadores_txt.append({
'nombre_apellido': nombre_apellido,
'velocidad': velocidad,
'posicion_cancha': posicion_cancha,
'nivel_jugador': nivel_jugador,
'edad': edad
})
# print(f"Jugadores cargados desde {archivo}")
except FileNotFoundError:
print(f"El archivo {archivo} no existe. Se creará uno nuevo al guardar jugadores.")
return jugadores_txt
# return None