Ask Your Question
2

How to re-use value from interact?

asked 2019-09-10 05:17:24 -0500

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
1

answered 2019-09-10 06:58:49 -0500

tmonteil gravatar image

You can try with global variables, something like:

Cell 1

a = 3

Cell 2

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

Cell 3

a1
edit flag offensive delete link more

Comments

Great, thanks!

Ingo gravatar imageIngo ( 2019-09-10 07:12:56 -0500 )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: 2019-09-10 05:17:24 -0500

Seen: 25 times

Last updated: Sep 10