Python Forum
Python Exercise Doubt - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Exercise Doubt (/thread-26101.html)



Python Exercise Doubt - azure - Apr-21-2020

Hi everyone,

I got a question for you guys, I've been dealing with this Python exercise since this morning but yeah! I'm completely stuck so I came here to get some advice since I don't have any clue about how to get this exercise done!

I need to print out only every second character of the string. Can someone teach me how to code this exercise?

Thank you, guys!


RE: Python Exercise Doubt - anbu23 - Apr-21-2020

Can you post what you have tried?


RE: Python Exercise Doubt - azure - Apr-21-2020

This is what I tried!

line = input('Please introduce a string: ')
result = line[0]
for i in range(2, len(line), 2):
result += ' ' + line[i]
print(result)

I need to print out "Hello World"

The result must be like the example shown below:

Every second character

Hello World -- > Input

el ol --> Result

(Apr-21-2020, 12:37 PM)anbu23 Wrote: Can you post what you have tried?

This is what I tried!

line = input('Please introduce a string: ')
result = line[0]
for i in range(2, len(line), 2):
result += ' ' + line[i]
print(result)

I need to print out "Hello World"

The result must be like the example shown below:

Every second character

Hello World -- > Input

el ol --> Expected Result


RE: Python Exercise Doubt - anbu23 - Apr-21-2020

line = input('Please introduce a string: ')
result = ""
for i in range(1, len(line), 2):
 result += ' ' + line[i]
print(result)



RE: Python Exercise Doubt - azure - Apr-21-2020

(Apr-21-2020, 01:02 PM)anbu23 Wrote:
line = input('Please introduce a string: ')
result = ""
for i in range(1, len(line), 2):
 result += ' ' + line[i]
print(result)

It works perfectly!

Thank you so much for your help!