+ 1
can some one help me out what is wrong whith this code?
def pal(n): rev=0 temp=n while temp>=1: div=temp%10 rev=(rev*10)+div temp=temp/10 print(rev) if rev==n: print("pal") else: print("not pal") print(pal(121)) program for palindrome
4 ответов
+ 3
I'm not sure of the best way to do it with mathematical operations, but you could make it work easily by turning your integer into a string, reversing the string, and comparing the two:
def pal(n):
n = str(n)
rev = n[::-1]
if n == rev: print("pal")
else: print("not pal")
pal(121)
+ 3
It's because Python automatically converts int types to float for division. If you want integer floor division like other languages do by default then you have to specify it in Python. Use:
temp=temp//10
0
Can you post the output please?
0
the output i'm getting is 122.26
the actual output should be 121
yes, for strings we can use reverse()
in java this code is working but not in python
anyone can give the detail explanation?