Can you explain the following code, it reverses a no but I don’t know how it works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can you explain the following code, it reverses a no but I don’t know how it works?

n=12345 rev=0 while(n>0): dig=n%10 rev=rev*10+dig n=n//10 print("Reverse of the number:",rev)

7th Sep 2019, 5:24 AM
Parvinder Rathore
3 Answers
+ 9
it takes the left digit using reminder operator then multiple it with 10 to add the next digit at the right usually I understand codes by printing the changes check this may help https://code.sololearn.com/c6Tgr225h1Ea/?ref=app
7th Sep 2019, 6:15 AM
ABADA S
ABADA S - avatar
+ 8
welcome
8th Sep 2019, 1:35 PM
ABADA S
ABADA S - avatar
+ 2
thank you both of you for your support , I am new to coding , your help really counts ~ swim ~ thank you , I didn’t downvoted your answer intentionaly may be it was something in haste though I realised my mistake now . I would look forward for your help in future
8th Sep 2019, 1:34 PM
Parvinder Rathore