1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Objective: Count and print the number of lines in a file [closed]

Discussão em 'Python' iniciado por Stack, Setembro 15, 2025.

  1. Stack

    Stack Membro Participativo

    Question:

    Count Lines in a File Objective: Count and print the number of lines in a file.

    Instructions:

    Use the attached text file "file1.txt"

    Write a Python script that opens the file, reads through it line by line, counts how many lines it has, and prints the total count.

    Expected result:

    Total number of lines: 5

    Error details:

    'Total number of lines: 5' != 'Total number of lines: 0'

    • Total number of lines: 5 ? ^
    • Total number of lines: 0 ? ^ : You must print the total number of lines in file1.txt.

    Expected result:

    Total number of lines: 5 This topic is covered in

    Continue reading...

Compartilhe esta Página