-2

Here is what I've tried :

i = 1
text = str(input())
for i in range(nbLignes):
   if i % 2 != 0:
      print(text)

I couldn't find any answer else where

Kwame
  • 3
  • 1

2 Answers2

0

if you have some text (with new lines) you can print every second line by splitting the str by lines and then use index slicing to pick only every second line starting from index 1

text = """line 1
line 2
line 3
line 4
line 5
line 6
line 7"""


for line in text.splitlines()[1::2]:
    print(line)

OUTPUT

line 2
line 4
line 6
Chris Doyle
  • 10,703
  • 2
  • 23
  • 42
0

If I understand correctly, you want to print the input every every other time in the range. If so, then most of your code is correct. Add just one line:

i += 1

after the if statement. This adds 1 to i, so in the next loop it becomes 2 and so on. Since you didn't add to i, i's value remained 1 and so didn't print.

Ismail Hafeez
  • 730
  • 3
  • 10