我偶然发现了欧拉计划。 这是我Problem 4的代码:
def find():
for a in range(999,99,-1):
for b in range(999,99,-1):
v = a * b
if str(v) == str(v)[::-1]:
print (v)
我的控制台虽然没有显示任何结果:/。有人可以帮忙吗?
答案 0 :(得分:0)
This is problem 4 in project euler,稍微修改一下代码,就会运行:
def find():
n = 0
for a in xrange(999, 100, -1):
for b in xrange(a, 100, -1):
x = a * b
if x > n:
s = str(a * b)
if s == s[::-1]:
n = a * b
print n
find()
答案 1 :(得分:0)
要显示结果,需要在定义后调用python中的函数/方法
def find():
for a in range(999,99,-1):
for b in range(999,99,-1):
v = a * b
if str(v) == str(v)[::-1]:
print (v)
find() //Calls the function find()