3 Comments

inputstring = "Hello and welcome to donuts"

newstring = ''

for c in inputstring:

newstring = c + newstring

print(newstring)

Expand full comment

My solution (I'm colombian):

"""

Autor: Juan Sebastian Valencia Londoño

Your task for today is to write some code that reverses any string.

There are two fundamentally different ways to accomplish this,

one using a for-loop and another using string slicing.

If you can, write both solutions.

"""

def reversed_string_1(string):

"""

Se usa el manejo de strings para retornar el string

:param string: str

:return: str

"""

reversed_string = string[::-1]

return f'The reversed string is: {reversed_string} - with algorithm 1'

def reversed_string_2(string):

reversed_string = []

for i in range(len(string)-1, -1, -1):

reversed_string.append(string[i])

reversed_string = ''.join(reversed_string)

return f'The reversed string is: {reversed_string} - with algorithm 1'

print(reversed_string_1('Hola retorname en reversa'))

print(reversed_string_2('Hola retorname en reversa'))

Expand full comment

### method 1

text = "Python is fun!"

text_reversed = text[::-1]

print(text_reversed)

###method 2

reversed_text = ""

for char in range(len(text) - 1, -1, -1):

reversed_text += text[char]

print(reversed_text)

Expand full comment