My first post here, im working on a proyect and i need to append the data from CARGAR(n, vec) into the vec, i tried append but it doesnt work! I need help. Did i miss something? I randomly select the times and i make an average called suma_t, then i make a variable called carrera with a str version of all the data.
import random
def mostrar_menu():
print("-------------------------------------------------------------------------")
print(" MENU ")
print("1. Cargar ")
print("2. Listar ")
print("-------------------------------------------------------------------------")
def validar_positivo():
n = int(input("Cuantos corredores hay?: "))
while n <= 0:
print("ERROR! Numero invalido")
return n
def cargar(n, vec):
for i in range(n):
numero = str(i+1)
nombre = str(input("Ingrese el nombre del corredor " + numero + ": "))
tiempo_1 = random.randint(0, 60)
tiempo_2 = random.randint(0, 60)
tiempo_3 = random.randint(0, 60)
suma_t = tiempo_1 + tiempo_2 + tiempo_3
tiempo_t = suma_t/3
print("Su tiempo promedio es de", tiempo_t)
carrera = str(nombre), str(tiempo_1), str(tiempo_2), str(tiempo_3), str(tiempo_t)
vec.append(carrera)
main()
def ordenar(vec):
n = len(vec)
for i in range(0, n-1):
for j in range(i+1, n):
if vec[i].tiempo_t < vec[j].tiempo_t:
vec[i], vec[j] = vec[j], vec[i]
def main():
vec = []
a = 0
while a != 3:
mostrar_menu()
a = int(input("Ingrese su opcion: "))
if a == 1:
n = validar_positivo()
cargar(n, vec)
if a == 2:
ordenar(vec)
if not vec:
print("Llene la lista")
else:
print(vec)
if a == 3:
print("Adios!")
if __name__ == "__main__":
main()