Search code examples
pythonstringpython-3.xuser-input

How to print every third line of some text input by user from keyboard?


So basically this is the specific question:

Write a Python program that reads input from the keyboard (standard input). The input will consist of some number of lines of text. The input will be terminated by a blank line. Your program should print every third line.

For instance, if the input is the following:

Please see this image!


Solution

  • You can take input using input() function and check blank line checking the line is empty string or not

    i = 1
    while 1:
        line = input()
        if line=='':
            break
        if i%3 == 0:
            print(line)
        i = i+1