How to write a python code that collects user input(which is a word) and then outputs it backward | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to write a python code that collects user input(which is a word) and then outputs it backward

WRITING WORD BACKWARDS

22nd Jan 2021, 9:42 AM
Ozemoka Shuaib Aloaye
Ozemoka Shuaib Aloaye - avatar
5 Answers
+ 3
word = input() rev_word = word[::-1] print(rev_word) # For example I input "Hello" : Output: >> olleH
22nd Jan 2021, 10:08 AM
noteve
noteve - avatar
+ 5
word = word[ : : -1] Parameters: word [ start_index : end_index : steps ] The start_index and end_index is not specified so by default it is 0 and end of the string respectively. Then -1 means 1 step backward (negative). That is also equivalent to this: ---> word = word[ 0 : len(word) : -1 ] Other method: ---> word[::-1] = word # This reverses the string without changing the memory address.
22nd Jan 2021, 9:46 AM
noteve
noteve - avatar
+ 2
So write like an example code please
22nd Jan 2021, 10:05 AM
Ozemoka Shuaib Aloaye
Ozemoka Shuaib Aloaye - avatar
+ 1
Thanks alot i really appreciate
22nd Jan 2021, 10:09 AM
Ozemoka Shuaib Aloaye
Ozemoka Shuaib Aloaye - avatar
+ 1
If you want to do that with code instead of slicing.....you can do that like this- s = input () rev = '' for i in range(len(s)): rev +=s[-(i+1)] print(rev)
22nd Jan 2021, 10:32 AM
Surkhab Khan
Surkhab Khan - avatar