Ciao a tutti
sto facendo un progetto per università
nome dello studente, presente, assente, giustificato
INTR8025.txt
Pluto Cristina,0,0,0
Pippo Luigi,0,0,0
Minnie Anna,0,0,0
output sarebbe:
Studente n.1 Pluto Cristina
1.Presente
2.Assente
3.Giustificato
Quindi é un professore che aggiorna di volta in volta il calendario delle presenze...
Io ho creato una lista da cui prendo solo i nomi che mi servono per la prima riga (studente n. 1.....)
Poi una formula per leggere una riga per volta (Pluto Cristina,0,0,0)
ho capito come aggiornare di uno il valore 0 ogni volta che il prof va su presente, assente giustificato, ma mi da errore perchè dice che non si può mischiare le stringhe e integer... di seguito il codice...
module = open('INTR8015.txt', 'r')
stu_name = [] # list name of each student each line
for i in module:
stu_name.append(i.split(',')[0]) # first word in each line
- is the first name in the first line
stu_name = [c.replace(',', ' ') for c in stu_name] # remove comma
print(f"Student #1: {stu_name[0]}")
with open('INTR8015.txt') as fileVar: # named each line Variable_0 first line student 1
variable_0 = [] # pack in a list
variable_0 = fileVar.read().split('\n')[0] # [1] if you want to read second line... insert n of line
assigne= 0
while assigne != 3:
try:
assigne = int(input("1: Present\n2. Absent\n3. Excused\n===> "))
if assigne == 1:
cris = [] # Empty list to refill
i = variable_0 [3] # index (4)
b = i + 1 # store in b the index 3 + 1
cris.append(b) # store the result in a list cris
variable_0 [3] = b # on the list n the 3 index have to be b
print(variable_0)
PLEASE HELP!!! Grazie!