Write a programExercise 1/4Basic10 XP

Searching a file

Task

The file kniha.txt contains text. The program reads a word from the input and prints every line of the file that contains it (also as part of a longer word), each with its line number as number: line - lines are numbered from 1. Finally it prints Nájdené riadky: N (lines found). The search is case-sensitive.

For the file

Python je programovací jazyk.
Program je postupnosť príkazov.
Cyklus opakuje príkazy.
Každý program treba otestovať.

and the word program the program prints:

1: Python je programovací jazyk.
4: Každý program treba otestovať.
Nájdené riadky: 2

Examples

  • Input

    program

    Expected output

    1: Python je programovací jazyk.
    4: Každý program treba otestovať.
    Nájdené riadky: 2

After you submit, 4 hidden tests will also check your solution: a capital letter, the word is not found, in every line, the last line without a newline.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.