Note: No comma at the end of the reversed word.
Enter word: Harry
The reversed word is: y,r,r,a,H
Python keep it simple
Code:
#take the input from user
word=input("enter the word you want to reverse: ")
#store the len of string in variable l
l=len(word)
#now create an empty string to store the result
out=""
#now start from the end of the string and decrement -1
#till we reach the starting index of the string
for i in range(l-1,-1,-1):
#append each character to the empty string
out= out+word[i]
#if the character is the last character then break the
loop
if(i==0):
break
#append a comma after appending every character
out=out+","
#now print the output
print("The string after modifying is: ")
print(out)
Output:
Code Screenshot:
Code Snippet:
#take the input from user
word=input("enter the word you want to reverse: ")
#store the len of string in variable l
l=len(word)
#now create an empty string to store the result
out=""
#now start from the end of the string and decrement -1
#till we reach the starting index of the string
for i in range(l-1,-1,-1):
#append each character to the empty string
out= out+word[i]
#if the character is the last character then break the loop
if(i==0):
break
#append a comma after appending every character
out=out+","
#now print the output
print("The string after modifying is: ")
print(out)
Get Answers For Free
Most questions answered within 1 hours.