1 | initial version |
for k in range(2,n + 2,2):
print(eval("P_%s"%k))
Ugly, I admit. It's hard to just stick in these things. Niles' solution is better.
2 | No.2 Revision |
for k in range(2,n + 2,2):
print(eval("P_%s"%k))
Ugly, I admit. It's hard to just stick in these things. Niles' solution is better.
Edit: But if you insist (I note you also used print
in your original example, so it was hard to anticipate your next issue)...
sage: n = 5
sage: P = list(var('P_%d' % i) for i in range(2*n + 1))
sage: for k in range(2,n + 2,2):
....: tem = eval('P_%s' %k)
....: x.subs(x=tem)
....:
P_2
P_4
P_6