Computer Science, asked by pankajkumar7812, 10 months ago

Write a simple python program to take input from the user and then print it's length and reverse using for loop and len function.


# The required output is as:
Please input your text to print it's reverse
Your inputted string is: E and ICT Academy
The reverse of the inputted string is: ymedacA TCI dna E​

Answers

Answered by mad210219
3

Given:

length and reverse

To find:

A simple python program to take input from the user and then print it's length and reverse using for loop and len function.

Solution:

Res=’’

S=input()

print(“the length is”,len(S))

x=len(S)

for i in reversed(range(x)):

    res+=S[i]

print(res)

OUTPUT:

Hello

The length is:5

olleH

is the string in reverse order

we use length len() function to print the length o f the string

we use reversed for loop to iterate from back to front so the

reverse of Hello is  

olleH

reversed(range(x))

means the loop run for 5 times from back to first

so each time the character is accessed and is added to resukt string  

So after all iterations we print the value of the string after reversal

Answered by yakash20dec
0

Answer:

userinput=input("Please input your text to print it's reverse\n")

print ("Your inputted string is: ",userinput)

str1=" "

for i in userinput:

   str1= i + str1

print ("The reverse of the  inputted string is:",str1)

Explanation:

output :-

Please input your text to print it's reverse

Your inputted string is:  E and ICT Academy

The reverse of the inputted string is:

ymedacA TCI dna E

Similar questions