Ask Your Question
0

Question about ordered pairs and dictionaries.

asked 2012-11-16 15:25:48 +0100

Siramok gravatar image

updated 2012-11-17 08:59:20 +0100

calc314 gravatar image

Hello, what I am trying to do is use (math) functions within functions that are defined by ordered pairs. The code I have looks like this:

f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1} g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}

show(g[f[g[0]]])

So, the way I intend for this to work is g[0] should return 0, which will become f[0] which returns 1, which becomes g[1] which should return -3. When I try to run this in sage 5.4, nothing appears to happen. Any help would be really great, thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-11-16 21:15:47 +0100

fidbc gravatar image

updated 2012-11-16 21:59:25 +0100

Hi, the code above seems fine, the output of the show function was a pdf file containing -3. Maybe just

f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
g[f[g[0]]]

If you want the result printed then

f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
print g[f[g[0]]]
edit flag offensive delete link more

Comments

I really appreciate you checking it, but strangely enough, now when I try evaluating the above code I get an error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_3.py", line 8, in <module> _interact_.SAGE_CELL_ID=1 NameError: name '_interact_' is not defined

Siramok gravatar imageSiramok ( 2012-11-16 21:42:14 +0100 )edit

The code in your question contains a syntax error and I can't edit it. I'll update the answer above to include it.

fidbc gravatar imagefidbc ( 2012-11-16 21:57:03 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-11-16 15:25:48 +0100

Seen: 547 times

Last updated: Nov 17 '12