Is it possible to use a variable to define another variable? I am trying to pick a random question to display from a list of questions but I don’t want to use a “when” statement because I want to easily add more questions without editing a “when” statement to include the new values. Code attempt below:
quantity = 3
r=randomGenerator()
num = r.int(1,quantity)
qNum = “q${num}”
aNum = “a${num}”
question1 = ${"${qNum}"}
answer1 = ${"${aNum}"}
q1 = “Here is question 1”
a1 = “Here is answer 1”
q2 = “Here is question 2”
a2 = “Here is answer 2”
q3 = “Here is question 3”
a3 = “Here is answer 3”
Off-topic a little bit but I think text ‘objects’ (so they can be stored in lists, accessed dynamically as labels, etc.) and text manipulation would be one of the items, if not the item, at the top of my Desmos feature wishlist.
There isn’t any way to access them from the list though. You can dynamically define labels, but it is more to do with the numeric values being dynamically set than a text string itself. I also would like more text manipulation, and more dynamic ways of dealing with tables.
Not currently but that’s kind of my point. It could streamline so many processes if you could store and access text in a list - eg. imagine having L=["alpha","beta","gamma","delta","epsilon"] and being able to just set up P=(0,[5...1]) with the label L. This would be far more efficient than manually creating the five points and editing each label.
Similarly, if we could use something like p_lural={n>1:"apples","apple"} and set up the label to be ${n} ${p_lural}, it opens up a world of dynamic labelling beyond what’s currently possible/easy to implement.
Just reading through this and what about this work around:
Create a linear function and then create points along the linear function using any increment : e.g (0,0), (10,10), (20,20) etc.
label each of those points with the question you want to ask.
randomly generate a number between 1 and however many points you have.
Make sure the graph component is displayed and bounds are set to within +/- 2 (or whatever appropriate) of that question (on the x and y) with the focal point being that point on the line"
The graph component will then display the labelled point +/- however large the window you want is.
I think if you do it that way you just add questions ad hoc whenever you want to in the graph component and then increase the interval in which you want to generate random numbers with.
The questions are tied to points that are every 10 units along a horizontal line.
Ditto with the answers
To add a questions/answers you change the end of the list “p_x” to whatever is appropriate (eg 17 questions need 160)
Add additional points using notation p1[“question number”] and label with question (ditto with answers except p2 is the answer line for points).
Hmm… that’s a really clever idea! Though I’m wondering if it’s actually less time consuming to make than using the whens? Since text is not supported well, I guess any solution is going to have some grindy nature to it.
I agree. I think it may take more processing time from a coding perspective, but it’s probably pretty negligible. I find it easier to read the CL over the graph expressions, and would probably choose when-otherwise for that reason alone.
The scalability is definitely limited by the way strings/text output on labelled points.
I just tried to do another work around where I had named note components (q1, q2, etc) and pulled one of them randomly on another page through random number generation but even that is not possible as soon as something is in a “string” in desmos, it can’t be used for object dot notation.
If I type: q1.script.question - it will pull that variable
however when I tried:
number=r.int(1,10)
reference=“q${number}”
reference.script.question - this didn’t work
I used “pointlabel”. This way would allow all the text/latex to be written in the CL layer. Probably a bit more user friendly. It’s just for the “answers” right now so click show answer and you’ll see the changed approach.
In terms of building this from ground up, the upfront time consumption would be manually inputting all the points and then after that adding them adhoc to the CL layer as needed and changing the randomly generated number range.
Instead of setting the length, l, by list p_x. I would define the length in the CL, and define the list in the graph as p_x=[0,10...10*(l-1)]. (Gosh I dislike l as a variable). Then, I would pre-define the p’s and q’s up to 30 or whatever I think is a reasonable number of questions for a bank (and note that cap in the CL). That way I don’t need to edit the graph as well, just the pointLabels and the number of questions, l, in the CL.
I would also pair the questions with answers in the CL for ease of additional entry (i.e. alternate points p1, q1, p2, q2…)