Discuss / Python / 自己写的作业,简单易懂

自己写的作业,简单易懂

Topic source

我有疫苗

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

def is_palindrome(n):

# 把整数换成字符
this_str = str(n)
# 求长度
str_len = len(this_str)
# 基数变成偶数 去掉中间位 /是做真除法 
if str_len % 2 != 0:
    this_str = this_str[:str_len//2+1]+this_str[str_len//2+1:]
    str_len = len(this_str)
# 从第一个开始遍历
i = 0
m = str_len/2-1
# 就算只有一位数字也对
while i <= m:
    if this_str[i] != this_str[str_len-i-1]:
        return False
    i = i + 1
return True

我有疫苗

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

我看评论有的一行代码就解决这个问题了 惭愧

NoArya

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

哈哈,解释的挺清楚


  • 1

Reply