Ask Your Question

How to re-use value from interact?

asked 2019-09-10 12:17:24 +0100

Ingo gravatar image

I have 3 subsequent SageMath code cells C1, C2, C3 in a Jupyter notebook.

  1. C1 sets a value a=1
  2. C2 has an interact widget (say a slider for a1) using the value of a as default
  3. C3 should assign the current value of a1 to a and proceed.

What do I have to write in C3 to access the current value of a1 in C2?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-09-10 13:58:49 +0100

tmonteil gravatar image

You can try with global variables, something like:

Cell 1

a = 3

Cell 2

def square(n):
    global a1
    print("{} squared is {}".format(n, n*n))
    a1 = n

Cell 3

edit flag offensive delete link more


Great, thanks!

Ingo gravatar imageIngo ( 2019-09-10 14:12:56 +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


Asked: 2019-09-10 12:17:24 +0100

Seen: 204 times

Last updated: Sep 10 '19