1,使用Python解决数学问题。
ABCD乘9 = DBCA 那么 A=?,B=?,C? D=?
for A in range(1,10): for B in range(0,10): for C in range(0,10): for D in range(1,10): if (A*1000 + B * 100 + C * 10 +D)* 9 == (D*1000 + C*100 +B*10 + A): print(‘{0}{1}{2}{3}*9 == {3}{2}{1}{0}‘.format(A,B,C,D))
2,使用python求阶乘的和。
0!+1!+2!+3!+4!+....+n!
def fact(n): if n == 0: return 1 return n * fact(n-1) while True: result = 0 n = input(‘Please input number:‘) if not n.isdigit(): print(‘你输入的不是纯数字,请重新输入!‘) continue for i in range(0,int(n)+1): result+=fact(i) print(result)