# character table of a finite field

I am trying to calculate the character table of a finite field. The following is my code:

```
def character_table(q,n):
k=GF(q^n)
tr(x)=sum(x^(q^i) for i in [0..n-1])
ksi = e^(2*pi*I/n)
chi(x)=ksi^(tr(x))
for a in k:
L_a = [chi(a*x) for x in k]
print L_a
```

And the TypeError is "free variable 'x' referenced before assignment in enclosing scope". Can somebody help me how to fix the code?

Thanks

Blockquote

Beyond the error that you are getting, here are some comments.

The function definition's body (everything below the first line) should be indented four spaces.

You define

`L`

but never use it.Are

`k`

and`K`

supposed to be the same?You are aware that Sage has finite group character tables via GAP as well, correct?

@slelievre I fixed all your suggestions. Now I get "free variable 'x' referenced before assignment in enclosing scope". @kcrisman I tried that but I couldn't get the right syntax. Could you please help? It seems that character_table() does not have an attribute for abelian groups. Also, since I am new in sage, I thought it was worth it to try and define a function from scratch. I also having difficulties on using only the additive group of a finite field.

Ah, then see my answer (which is just a link).

@slelievre Please see the edited question.