Python - Ayuda

 
Vista:

Ayuda

Publicado por hideki (4 intervenciones) el 06/12/2021 06:40:59
Alguien me puede ayudar en este codigo, lo que deveria hacer es poner la cantidad de alumnos por salon los codigos de cada uno, sus notas, promedio y ponerlo en un .txt

def salon_uno(x):
alumnosuno= []
for i in range(n):
codigo = int(input("Ingrese el codigo del alumno: "))
nota1 = float(input("Ingrese la nota 1 del alumno: "))
nota2 = int(input("Ingrese la nota 2 del alumno: "))
nota3 = float(input("Ingrese la nota 3 del alumno: "))
return alumnouno

def salon_dos(y):
alumnosdos = []
for i in range(n):
codigo = int(input("Ingrese el codigo del alumno: "))
nota1 = float(input("Ingrese la nota 1 del alumno: "))
nota2 = float(input("Ingrese la profe soy cabro del alumno: "))
nota3 = float(input("Ingrese la nota 3 del alumno: "))
return alumnosdos

def salon_tres(z):
alumnostres = []
for i in range(n):
codigo = int(input("Ingrese el codigo del alumno: "))
nota1 = float(input("Ingrese la nota 1 del alumno: "))
nota2 = float(input("Ingrese la nota 2 del alumno: "))
nota3 = float(input("Ingrese la nota 3 del alumno: "))
return alumnostres

def main():
x = int(input("Ingrese cuantos alumnos hay en el salon A: "))
y= int(input("Ingrese cuantos alumnos hay en el salon B: "))
z = int(input("Ingrese cuantos alumnos hay en el salon C: "))
salon_A(A)
salon_B(B)
salon_C(C)

if name=="main":
main()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Francisco Javier
Val: 249
Ha aumentado su posición en 29 puestos en Python (en relación al último mes)
Gráfica de Python

Ayuda

Publicado por Francisco Javier (313 intervenciones) el 06/12/2021 10:38:37
Te he puesto sólo dos salones pero puedes añadir los que quieras.

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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import io
from io import open
 
def salon_uno():
    alumnosuno= []
    codigo = int(input("Ingrese el codigo del alumno: "))
    nota1 = float(input("Ingrese la nota 1 del alumno: "))
    nota2 = float(input("Ingrese la nota 2 del alumno: "))
    nota3 = float(input("Ingrese la nota 3 del alumno: "))
    alumnosuno.append([f'codigo:{codigo}\nnotas: {nota1},{nota2},{nota3}\nmedia:{(nota1+nota2+nota3)/3}\n'])
    return str(alumnosuno)
 
def salon_dos():
    alumnosdos = []
    codigo = int(input("Ingrese el codigo del alumno: "))
    nota1 = float(input("Ingrese la nota 1 del alumno: "))
    nota2 = float(input("Ingrese la nota 2 del alumno: "))
    nota3 = float(input("Ingrese la nota 3 del alumno: "))
    alumnosdos.append([f'codigo:{codigo}\nnotas: {nota1},{nota2},{nota3}\nmedia:{(nota1+nota2+nota3)/3}\n'])
    return str(alumnosdos)
 
fichero=open('listados.txt','w')
fichero.write('LISTADO DE ALUMNOS DE LOS DOS SALONES\n')
fichero.close()
salon=int(input('Ingrese 1 o 2 según el salón quieras ingresar alumnos: '))
ingreso=int(input(f'¿Cuántos alumnos quieres ingresar en el salón {salon}? '))
if salon==1:
    for i in range(ingreso):
        fichero=open('listados.txt','a')
        fichero.write(salon_uno())
        fichero.write('\n')
        fichero.close()
 
elif salon==2:
    for i in range(ingreso):
        fichero=open('listados.txt','a')
        fichero.write(salon_dos())
        fichero.write('\n')
        fichero.close()
 
else:
    print('Creo que ha habido un error')
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Francisco Javier
Val: 249
Ha aumentado su posición en 29 puestos en Python (en relación al último mes)
Gráfica de Python

Ayuda

Publicado por Francisco Javier (313 intervenciones) el 06/12/2021 10:45:39
Buenas lo he arreglado un poco para hacerlo mas eficiente, no hace falta poner cada uno por salon de esta maneras puedes añadir el numero de salones que quieras. Un saludo
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import io
from io import open
 
def datos():
    alumnosuno= []
    codigo = int(input("Ingrese el codigo del alumno: "))
    nota1 = float(input("Ingrese la nota 1 del alumno: "))
    nota2 = float(input("Ingrese la nota 2 del alumno: "))
    nota3 = float(input("Ingrese la nota 3 del alumno: "))
    alumnosuno.append([f'codigo:{codigo}\nnotas: {nota1},{nota2},{nota3}\nmedia:{(nota1+nota2+nota3)/3}\n'])
    return str(alumnosuno)
 
 
fichero=open('listados.txt','w')
fichero.write('LISTADO DE ALUMNOS DE LOS DOS SALONES\n')
fichero.close()
salon=int(input('Ingrese el numero del salón en el que quieras ingresar alumnos: '))
ingreso=int(input(f'¿Cuántos alumnos quieres ingresar en el salón {salon}? '))
for i in range(ingreso):
    fichero=open('listados.txt','a')
    fichero.write(f'salon {salon}\n{datos()}\n')
    fichero.close()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar