-1

this is my code:


lista_serie_fibonacci=[1, 2, 3, 5, 8, 13, 21, 34, 55, 89]


with open('archivo_lista_ordenada', 'w') as contenido_ordenado:
  contenido_ordenado.write(lista_a_cadena)
  
f = open("archivo_lista_ordenada", "r")
while(True):
    linea = f.readline(lista_serie_fibonacci)
    print(linea)
    if not linea:
        break
f.close()

How can I make it read the lines of the fibonachi list,I would really appreciate your help, I don't know what else to do :(

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 1
    Welcome to Stack Overflow. Please read [ask] and [mre]. It is not possible to answer the question properly, because right now there is no way we can know: 1) **What is in the file**? (What is `lista_a_cadena`? Where did it come from?) 2) **What should happen** when the code runs? Exactly what output do you want to see from each `print(linea)`? – Karl Knechtel Oct 08 '22 at 02:16

1 Answers1

0

Do you mean that you want to read the first line, then the 2nd, the 3rd, the 5th, and so on? This could be done by reading the lines one by one and just skipping those that are not of interest:

i = 1
while (True):
    linea = f.readline()
    if (not linea):
        break
    else:
        if (i in lista_serie_fibonacci):
            print (linea)
    i += 1