我想知道,如果有可能创建变量并在Python上命名使用字符串和其他变量.这对我正在帮助我真的很有帮助.
例如,我想创建10个变量:
var0
var1
var2
...
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的"for"循环:
for i in range(10):
'var'+str(i) = 0
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误.请帮忙!
任何帮助将非常感激.
可能的重复:
为什么“返回自我”返回 None?
我一直在尝试解决 Project Euler 上的问题 55 ( http://projecteuler.net/problem=55 ),现在我想我已经找到了答案,但我遇到了一个问题。我不想要问题 55 的解决方案,只想要我做错了什么。
这是我的代码:(我认为您不需要全部)
t=0
lychrel=0
called=0
def iteratepal(n):
global t
global called
called+=1
b = int(''.join(reversed(str(n))))
#print ("n =",n,"\nb =",b,"\nb+n =",b+n,"\n")
if ispal(b+n) or ispal(n):
t=0
return False
if t<50:
t+=1
iteratepal(b+n)
else: # Here's the prob
t=0 # this block is executed (because it prints "yea")
print("yea") # but it doesn't return True!
return True # you can try it yourself (even in the interpreter)
def ispal(n):
if …Run Code Online (Sandbox Code Playgroud)