Difficult to get palindrome program executed

Hello, I’m trying to make a program to get the palindrome checked.

My initial code:
<
number=input("whether palindrome or not\nEnter the number: ")
number=int(number)
copy=number
rev=0

while number>0:
reminder=number%10
rev=rev*10+reminder
number=number/10

if copy==rev:
print(“The number “,copy,” is Palindrome.”)
else:
print(“The number “,copy,” is not palindrome.”)

My final code:
<
number=input("whether palindrome or not\nEnter the number: ")
number=int(number)
copy=number
rev=0

while number>0:
reminder=number%10
rev=rev*10+reminder
number=number//10

if copy==rev:
print(“The number “,copy,” is Palindrome.”)
else:
print(“The number “,copy,” is not palindrome.”)

I noticed when i’m using number=number/10
The output is not correct.
While when i use number=number//10
The output is correct.

Is there really difference between / and // while doing calculations in python.

It would be very helpful (and you are likely to get more responses) if you put your code between three back ticks like this:

number=input("whether palindrome or not\nEnter the number: ")
number=int(number)
copy=number
rev=0

If you do this people can see and run your code, and particularly see the indentation which often is the cause of problems.

The “//” will alwasy result in a whole number and is equivalent to taking the floor (rounding down) of the result after you have divided

the “/” will just give you the result of diving

For example:

print(123//10)
#12

print(123/10)
#12.3

Yes. There would not be two ways like this, if it did the same thing. // ignores any remainder, to give only the integer part. / gives a floating-point result, even with integer inputs. You could also verify this by yourself, by just trying it by itself instead of wondering :slight_smile:

Please see:

You have coded an answer. Well done!

To me (and the first on-line dictionary consulted) a palindrome is described in terms of words or letters, eg abba.

Did the training materials you have been using specify a numeric form?
Has your learning-plan included string processing and/or working with Python-lists?

Accordingly, (in ignorance of the above) could the input (number) be converted to a string, and would it be easier to check a string than to compute numerically?

Another alternative might be to decompose the number into a list of digits, and again, see if it might be easier to check the elements of a list?