Computer Science, asked by amavashayasu123, 3 months ago

Wap to reverse the string to 5mark in python
Can anyone tell me the answer

Answers

Answered by allysia
3

Language:

Python

Program:

a=str(input("Enter the string: "))

b=''

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

   b+=a[i]

a=b

print(a)

Output:

Enter the string: heythere

erehtyeh

Logic:

  • Accept the value in a variable.
  • reverse run a loop and keep concatenating the value in another variable initialize before.
  • Equal 1st variable to another.
  • Return the variable.

Answered by Rudranil420
3

Answer:

def reverse(s):

str = ""

for i in s:

str = i + str

return str

s = "Geeksforgeeks"

print ("The original string is : ",end="")

print (s)

print ("The reversed string(using loops) is : ",end="")

print (reverse(s))

Output:

The original string is : Geeksforgeeks

The reversed string(using loops) is : skeegrofskeeG

Similar questions