Creating activecode only so it can :include:d later

4 views
Skip to first unread message

Victor Norman

unread,
Nov 27, 2018, 7:06:51 AM11/27/18
to RunestoneInteractive
I am building a book that will only contain a large set of problems in python for students to use to practice their coding skills -- similar, I guess, to turingscraft.com.

I regularly want to have the students have to write code that assumes some other code exists and has been run.  E.g.,

 Assume you have two variables hours and hourly_rate. Write code to compute the total_pay, by multiplying hours and hourly_rate and storing in total_pay.

I don't want to give them the code that creates the two variables, hours and hourly_rate.

I know that I can do this by using :include: of another problem. However, I don't really want to have another problem that just has two lines of code in it, defining hours and hourly_rate and giving them values.

Is there a way to create a "hidden" activecode block so that it can be :include:d in another block?

Thanks.

Vic

Stephen Tate

unread,
Nov 27, 2018, 8:30:25 AM11/27/18
to runestonei...@googlegroups.com

If you just don't want the included code to show up in the presentation to the student, you can indeed hide it with some raw HTML. Here's what I did in a similar situation - first, make an activecode block with a name so you can include it later. Then to make is so that it doesn't display to the student, before the activecode you can put:

.. raw:: html

   <div style='display:none;'>

and after the activecode block put

.. raw:: html

   </div>

There may be a more elegant solution, but that works for me. Note that line numbers get messed up so error messages may be confusing to the student. If you're just including two lines, then why not just put them at the top of the code editor that the student will code in?

On the line number thing: At one point I figured out how to adjust it so that the student code editor would start numbering lines at a specific value (> 1), so that error messages would give the right line numbers. I never got around to making that a reliable addition to the code though, and I've been distracted away from Runestone for a while now so haven't given it much more thought.

--

Steve Tate
Head, Dept of Computer Science
University of North Carolina at Greensboro

Voice:  336-256-1033
Fax:  336-256-0439


--
You received this message because you are subscribed to the Google Groups "RunestoneInteractive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to runestoneinterac...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Norman

unread,
Nov 27, 2018, 9:45:23 AM11/27/18
to RunestoneInteractive
Stephen,

That works great!  Thanks!

I don't want to show the "before" code because I don't want the students to just write a statement that produces the correct solution, but in the wrong way.  E.g., if the question is to write a statement to add 1 to a variable temperature, and I give them the code

    temperature = 73.4

I don't want them to write

   temperature = 74.4

I want them to write 

   temperature = temperature + 1

Not giving them the "setup code" makes them write the latter, not the former, I think.

Vic
To unsubscribe from this group and stop receiving emails from it, send an email to runestoneinteractive+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages