First time here? Check out the FAQ!

Ask Your Question
2

How to re-use value from interact?

asked 5 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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
Preview: (hide)
link

Comments

Great, thanks!

Ingo gravatar imageIngo ( 5 years ago )

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: 5 years ago

Seen: 261 times

Last updated: Sep 10 '19