160k views
4 votes
Assume that the variable myString refers to a string, and the variable reversedString refers to an empty string. Write a loop that adds the characters from myString to reversedString in reverse order.

1 Answer

6 votes

Answer:

# The user input is accepted and stored in myString

myString = input(str("Enter your string: "))

# An empty string called reversedString is declared

reversedString = ''

# l is defined to show number of times the loop will occur.

# It is the length of the received string minus one

# since the string numbering index start from zero

l = len(myString) - 1

# Beginning of the while loop

while l >= 0:

reversedString += myString[l]

l = l - 1

# The reversed string is printed to the user

print(reversedString)

Step-by-step explanation:

User Damiya
by
5.8k points