python水仙花数,回文数

'''
从控制台输入一个3位数,如果是水仙花数就打印“是水仙花数”,否则
打印“不是水仙花数”
153=1^3+5^3+3^3
'''
num9 = int(input("请输入一个3位数:"))
b = num9 // 100
c = (num9 - b * 100) // 10
d = (num9 - b * 100 - c * 10)
#f = pow(b,3) + pow(c,3) + pow(d,3)
f = b**3+c**3+d**3
#f = b^3+c^3+d^3#为什么会出现12???
if num9 == f:
print(num9, "是水仙花数")
else:
print(num9, "不是水仙花数")
print("b=", b)
print("c=", c)
print("d=", d)
print("f=", f)


'''
从控制台输入一个5位数,如果是回文数就打印“是回文数”,否则
打印“不是回文数”
如:11111 12321 12221对称的数是回文数、

'''
num10=int(input("请输入您要判断的一个5位数:"))
a = num10 % 10
b = ((num10 % 100)-a)//10
c = num10 //10000
d = (num10 //1000)-(c*10)
if a==c:
if b==d:
print(num10,"是回文数。")
else:
print(num10,"不是回文数。")
else:
print(num10,"不是回文数。")
#打印出个数字,看数字是否出错了
print("a=",a)
print("b=",b)
print("c=",c)
print("d=",d)

猜你喜欢

转载自www.cnblogs.com/zlong123/p/10417658.html