Hii check my new code of reversing a no ......i am not getting the output ....plz help tell me my mistake ....plzzzzz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Hii check my new code of reversing a no ......i am not getting the output ....plz help tell me my mistake ....plzzzzz

14th Jun 2019, 5:30 PM
AAYUSH PAGARE🇮🇳
AAYUSH PAGARE🇮🇳 - avatar
4 Answers
+ 3
There is a much more elegant way of reversing not only numbers but any string. https://code.sololearn.com/c07DIdGKX2PP/?ref=app
14th Jun 2019, 6:08 PM
Amit Robert Baroi
Amit Robert Baroi - avatar
+ 4
The first problem is, that not= isn't really an operator, you should do not x == 0 Second problem is, that the loop would never end because you only divide it by ten, and dividing by a number won't ever return 0. You should do: x //= 10 or x = x // 10 (floor division) The third problem is, that it prints all the digits are printed in seperate lines, you should do print(rem, end = "") The fourth problem is, that you could do it in one line: print(input()[::-1])
14th Jun 2019, 5:41 PM
Airree
Airree - avatar
+ 2
#enter any no the program will reverse your no #for eg no is 432 and program will show you 234 x=input("enter a no: "); i=len(x) #gets length of input to know how big number is rem=0 #declare rem as a number x=int(x) while x > 0 : #loop until all digits are processed rem+=(x%10)*(10**(i-1)) #adds the digit in its proper place x=x//10 #floor division is necessary to not get infinite decimals (and therefore not have an infinite loop) i=i-1 #decrement i to maintain proper digit placement print(rem) #print result Your main issue was not using floor division I believe
14th Jun 2019, 5:55 PM
Jackson O’Donnell
+ 2
This code prints the reverse of the entered number and concludes whether it is a palindrome or not. https://code.sololearn.com/cU7LJhyaG8o4/?ref=app
14th Jun 2019, 7:20 PM
Veda Shree S
Veda Shree S - avatar