[Tutor] reverse a number (was no subject)
Chris Kassopulo
ckasso@sprynet.com
Fri, 9 Aug 2002 21:05:30 -0400
On Fri, 9 Aug 2002 17:39:48 +0530
"Anand Ramakrishna" <anandrs@hexaware.com> wrote:
> Hi,
> I am having a strange problem with my python code for reversing a
> number. I tried it on a few combinations and works fine with most
> of them except when the number starts in '1'. If I give input as
> 123 it reverses and displays as 442. If I give input as 12 it
> reverses and displays as 12. Where as if I give any other number,
> it reverses properly and displays the correct result. The code is
> pasted below.
>
>
>
> print 'This program accepts a number and then reverses it'
> number = int(raw_input("Enter a number = "))
> temp_var = 0
>
> while (number/10) > 1 :
> temp_var = (temp_var*10) + (number%10)
> number = number/10
> else:
> temp_var = (temp_var*10) + number
> print 'The reversed number is ', temp_var
>
>
>
> Anbudan,
> Anand~
>
> ---------------------------------------------------------------------
> -------------- If you think you can't beat your computer at Chess, try
> kickboxing.
>
>
--
Chris Kassopulo _/\_ Linux User #199893 _/\_ Slackware