python判斷迴文數
迴文數定義即爲數字翻轉後仍爲原來的數字,那麼這個數字就是迴文數。
思路就是判斷對稱的數字是否相等。
代碼如下
a = input("請輸入數字: ")
b=len(a)
for i in range (b):
if(a[i]==a[b-i-1]):
c=1
else:
c=0
if(c==1):
print("這是迴文數")
else:
print("這不是迴文數")
迴文數定義即爲數字翻轉後仍爲原來的數字,那麼這個數字就是迴文數。
思路就是判斷對稱的數字是否相等。
代碼如下
a = input("請輸入數字: ")
b=len(a)
for i in range (b):
if(a[i]==a[b-i-1]):
c=1
else:
c=0
if(c==1):
print("這是迴文數")
else:
print("這不是迴文數")
class MetaCls(type): def __new__(cls, *args, **kwargs): print("in MetaCls") # return super(Meta