Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Exercise Doubt
#1
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!
Reply
#2
Can you post what you have tried?
Reply
#3
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
Reply
#4
line = input('Please introduce a string: ')
result = ""
for i in range(1, len(line), 2):
 result += ' ' + line[i]
print(result)
Reply
#5
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Doubt about conditionals in Python. Carmazum 6 1,615 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  A simple python doubt mohamedrabeek 2 734 Mar-26-2023, 07:24 PM
Last Post: deanhystad
  Headfirst Python Exercise GeorgeSears 3 1,407 Jun-11-2022, 06:36 PM
Last Post: GeorgeSears
  Wrong code in Python exercise MaartenRo 2 1,537 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  doubt about python tkinter and sqlite3 LONDER 2 2,157 Aug-14-2021, 08:48 AM
Last Post: ibreeden
  Python Doubt csrlima 5 2,612 Jan-23-2021, 12:23 AM
Last Post: csrlima
  New to python, having trouble with an exercise Salkay 3 2,168 Feb-18-2020, 01:42 AM
Last Post: Salkay
  Doubt in Regex Lookaround fullstop 3 2,393 Feb-03-2020, 09:53 AM
Last Post: Gribouillis
  A doubt with 'in' and 'not in' operators with strings newbieAuggie2019 7 3,610 Oct-23-2019, 03:11 PM
Last Post: perfringo
  OpenCV - Doubt in a line. ArjunSingh 1 2,501 Jul-14-2019, 03:36 PM
Last Post: ThomasL

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020