Discuss / Python / work 没有换成str,有点麻烦不过也行

work 没有换成str,有点麻烦不过也行

Topic source

程乔静

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

def is_palindrome(n): j=1 if n>10: while n/10**j>10: j=j+1 j=j+1

#判断整数的位数 i=int(n/(10**(j-1)))

#算出n整数的最高位值 while j!=0: z=n%10 j=j-1

#算出个位的整数用“%” d=j if i==z: m=int((n%(10**d))/10)

#去掉首位的数字 if m<10: return n else: return is_palindrome(m) else: return False

程乔静

#2 Created at ... [Delete] [Delete and Lock User]

copy 一个简单的:

def is_palindrome(n): s_n = str(n) return s_n == s_n[::-1] output = filter(is_palindrome, range(1, 10000)) print('1~10000:', list(output))


  • 1

Reply