Doubt with Python exercise

1

I have doubts about how to get to do this python exercise:

  

Using the notes.csv file, make a program in python that reads the data from that file and builds the following structure:

  alumnos = [ {"nombre":"Daniel", "apellidos":"Fustero López", "curso": "1A",
    "notas":{"FH":3,"LM":4,"ISO":5,"FOL":6,"PAR":7,"SGBG":6}},
         {"nombre":"Rafaela", ... }
       ,...]
     

Create a program that shows you a menu and you can choose one of these options:

     
  • Shows the list of students with the average grade they have taken. Use a function to calculate the average grade.
  •   
  • Ask for a course and a subject and show a list of the students of that course with the grades in that subject.
  •   
  • Request a course and show the percentage of passes for each subject.
  •   
  • Request a course, and create a file name of the course.txt with the students and the average grade.
  •   

At the moment I have this code but there is no way to get it out in any of the ways. How can I do it?

def recorrerLista():
listaNotas = []
primera = True
with open("notas.csv", "r") as fichero:
    for linea in fichero:
        if primera:
            primera = False
            continue
        else:
            alumnos = dict ()
            notas = dict ()
            listaLinea = linea.split(",")
            alumnos['Apellido'] = listaLinea [0]
            alumnos['Nombre'] = listaLinea [1]
            alumnos['Curso'] = listaLinea [2]
            notas['FH'] = listaLinea [3]
            notas['LM'] = listaLinea [4]
            notas['ISO'] = listaLinea [5]
            notas['FOL'] = listaLinea [6]
            notas['PAR'] = listaLinea [7]
            notas['SGBD'] = listaLinea [8]
            alumnos['notas'] = notas
            listaNotas.append (alumnos)
print (listaNotas)
recorrerLista()

I am completely stuck in everything, I do not know how to follow the program anymore. This is the .CSV file itself:

Nombre,Apellidos,Curso,FH,LM,ISO,FOL,PAR,SGBD
ACEVEDO JHONG, DANIE,1C,2,0,6,1,1,8
ALCALà NEGRÓN, CHRISTIAN NELSO,1C,3,0,6,10,9,9 
ALMORA HERNANDEZ, RAUL EDUARD,1D,4,3,1,3,3,8
    
asked by ShJod 28.01.2018 в 18:48
source

1 answer

0

Indeed, as you have been told by other colleagues, the question is too ambiguous and you should be more concise in the problem you have. Anyway, I have left you a small code that can serve as a reference. Obviously not all the options that you propose ... I hope I can be of help.

def leerFicheroCsv():
  f=open('alumnos.csv', 'r')
  try:
    return csv.DictReader(f, delimiter=';')
  except csv.Error as e:
    print ('Error al abrir fichero %s, error: %s' % (filename, e))
    time.sleep(2)


def notaMediaAlumnos():
    sum=0
    cont=0
    for row in leerFicheroCsv():
       cont+=1
       sum+=int(row['FH'])+int(row['LM'])+int(row['ISO'])+int(row['FOL'])+int(row['PAR'])+int(row['SGBD'])

print ("La nota media de los alumnos es: ", round(sum/cont/6, 2))
time.sleep(2)


def notaAsignaturaCurso(sign, curs):
    encontrado=False
    for row in leerFicheroCsv():
        try:
        if curs==row['Curso']:
            print ("%s%s tiene una nota de %s en la asignatura"  % (row['Nombre'], row['Apellidos'], row[sign]))
            time.sleep(1)
            encontrado=True
        except:
            print ("La asignatura %s no existe en el fichero CSV" % sign)
            time.sleep(3)
            encontrado=True
            break

if not encontrado:
    print ("El curso %s no existe en el fichero CSV" % curs)
    time.sleep(3)


def principal():

   opcion='0'

   while opcion!='3':
    print ("""
    Selecione una de las siguientes opciones: 
    1. Nota media de cada alumno
    2. Nota por asignatura y curso
    3. Salir del programa""")

    opcion=input("    Opción: ")

    if opcion=='1':
        notaMediaAlumnos()
    elif opcion=='2':
        asig=input("Introduzca Asignatura: ")
        curso=input("Introduzca Curso: ")
        notaAsignaturaCurso(asig, curso)
    elif opcion=='3':
        print ("Goodbye!!!")
        time.sleep(2)
    else:
        print ("Opción inválida. Vuelva a introducir opción...")
        time.sleep(2)

if __name__ == "__main__":
    principal()
    
answered by 30.01.2018 в 01:30