Skip to content

Commit

Permalink
Merge pull request RunestoneInteractive#107 from isaacdontjelindell/r…
Browse files Browse the repository at this point in the history
…eadyfor

Add 3-tabbed exercises to the SimplePythonData chaper
  • Loading branch information
bnmnetp committed May 29, 2013
2 parents 517d3eb + d0e8186 commit c87235a
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 80 deletions.
18 changes: 10 additions & 8 deletions modules/luther/sphinx/activecode/activecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,29 @@ def run(self):



EXEDIT = '''
<button id="butt_%(divid)s" onclick="createActiveCode('%(divid)s','%(source)s'); $('#butt_%(divid)s').hide();">Open Editor</button>
<div id="%(divid)s"></div>
<br />
'''

class ActiveExercise(Directive):
required_arguments = 1
optional_arguments = 0
has_content = True
option_spec = {}

def run(self):
self.options['divid'] = self.arguments[0]
self.options['caption'] = ''
self.options['include'] = 'undefined'

if self.content:
source = "\\n".join(self.content)

else:
source = ''
self.options['source'] = source.replace('"','%22').replace("'",'%27')

res = EXEDIT

self.options['initialcode'] = source.replace('"','%22').replace("'",'%27')
return [nodes.raw('',res % self.options,format='html')]

return_node = ActivcodeNode(self.options)
return [return_node]


if __name__ == '__main__':
Expand Down
15 changes: 15 additions & 0 deletions overview/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ from scratch and write your own interactive textbook using the tools that we pro
In order to see how the tools work, the following sections will show them in action.


.. tabbed:: randomdiv

.. tab:: Tab1

.. video:: videoinfo
:controls:
:thumb: _static/activecodethumb.png

http://media.interactivepython.org/thinkcsVideos/activecodelens.mov
http://media.interactivepython.org/thinkcsVideos/activecodelens.webm

.. tab:: Tab 2

hello world

Embedded Videos
---------------

Expand Down
1 change: 1 addition & 0 deletions source/Lists/lists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ item when counting the length of the list.


.. code-block:: python
alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False]
print(len(alist))
Expand Down
178 changes: 136 additions & 42 deletions source/SimplePythonData/simpledata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1256,36 +1256,68 @@ Glossary
Exercises
---------

1. Evaluate the following numerical expressions in your head, then use
the active code window to check your results:

#. ``5 ** 2``
#. ``9 * 5``
#. ``15 / 12``
#. ``12 / 15``
#. ``15 // 12``
#. ``12 // 15``
#. ``5 % 2``
#. ``9 % 5``
#. ``15 % 12``
#. ``12 % 15``
#. ``6 % 6``
#. ``0 % 7``

.. activecode:: ch02_ex1

print(5**2)
1.

.. tabbed:: q1

.. tab:: Question

Evaluate the following numerical expressions in your head, then use
the active code window to check your results:

#. ``5 ** 2``
#. ``9 * 5``
#. ``15 / 12``
#. ``12 / 15``
#. ``15 // 12``
#. ``12 // 15``
#. ``5 % 2``
#. ``9 % 5``
#. ``15 % 12``
#. ``12 % 15``
#. ``6 % 6``
#. ``0 % 7``

.. activecode:: ch02_ex1

print(5**2)

.. tab:: Answer

Put some sort of answer here!

.. tab:: Discussion

.. disqus::
:shortname: interactivepython
:identifier: q1disqus

2. You look at the clock and it is exactly 2pm. You set an alarm to go off
in 51 hours. At what time does the alarm go off?

.. actex:: ex_2_2

#. Write a Python program to solve the general version of the above problem.
Ask the user for the time now (in hours), and ask for the number of hours to wait.
Your program should output what the time will be on the clock when the alarm goes off.
#.

.. tabbed:: q3

.. actex:: ex_2_3
.. tab:: Question

Write a Python program to solve the general version of the above problem.
Ask the user for the time now (in hours), and ask for the number of hours to wait.
Your program should output what the time will be on the clock when the alarm goes off.

.. actex:: ex_2_3

.. tab:: Answer

Put some sort of answer here!

.. tab:: Discussion

.. disqus::
:shortname: interactivepython
:identifier: q3disqus

#. You go on a wonderful holiday
leaving on day number 3 (a Wednesday). You return home after 137 nights.
Expand All @@ -1297,51 +1329,113 @@ Exercises
# Problem 4
# My Name:

#. Take the sentence: *All work and no play makes Jack a dull boy.*
Store each word in a separate variable, then print out the sentence on
one line using ``print``.
#.

.. tabbed:: q5

.. tab:: Question

Take the sentence: *All work and no play makes Jack a dull boy.*
Store each word in a separate variable, then print out the sentence on
one line using ``print``.

.. actex:: ex_2_5

.. tab:: Answer

.. actex:: ex_2_5
Put some sort of answer here!

.. tab:: Discussion

.. disqus::
:shortname: interactivepython
:identifier: q5disqus

#. Add parenthesis to the expression ``6 * 1 - 2`` to change its value
from 4 to -6.

.. actex:: ex_2_6

#. The formula for computing the final amount if one is earning
compound interest is given on Wikipedia as
#.

.. tabbed:: q7

.. tab:: Question

The formula for computing the final amount if one is earning
compound interest is given on Wikipedia as

.. image:: Figures/compoundInterest.png
:alt: formula for compound interest

.. image:: Figures/compoundInterest.png
:alt: formula for compound interest
Write a Python program that assigns the principal amount of 10000 to
variable `P`, assign to `n` the value 12, and assign to `r` the interest
rate of 8% (0.08). Then have the program prompt the user for the number of years,
`t`, that the money will be compounded for. Calculate and print the final
amount after `t` years.

Write a Python program that assigns the principal amount of 10000 to
variable `P`, assign to `n` the value 12, and assign to `r` the interest
rate of 8% (0.08). Then have the program prompt the user for the number of years,
`t`, that the money will be compounded for. Calculate and print the final
amount after `t` years.
.. actex:: ex_2_7

.. actex:: ex_2_7
.. tab:: Answer

Put some sort of answer here!

.. tab:: Discussion

.. disqus::
:shortname: interactivepython
:identifier: q7disqus

#. Write a program that will compute the area of a circle. Prompt the user to enter the radius and print a nice message
back to the user with the answer.

.. actex:: ex_2_8

#. Write a program that will compute the area of a rectangle. Prompt the user to enter the width and height of the rectangle.
Print a nice message with the answer.
#.

.. tabbed:: q9

.. tab:: Question

Write a program that will compute the area of a rectangle. Prompt the user to enter the width and height of the rectangle.
Print a nice message with the answer.

.. actex:: ex_2_9
.. actex:: ex_2_9

.. tab:: Answer

Put some sort of answer here!

.. tab:: Discussion

.. disqus::
:shortname: interactivepython
:identifier: q9disqus

#. Write a program that will compute MPG for a car. Prompt the user to enter the number of miles driven and the number of
gallons used. Print a nice message with the answer.

.. actex:: ex_2_10

#. Write a program that will convert degrees celsius to degrees fahrenheit.
#.

.. tabbed:: q11

.. tab:: Question

Write a program that will convert degrees celsius to degrees fahrenheit.

.. actex:: ex_2_11

.. tab:: Answer

Put some sort of answer here!

.. tab:: Discussion

.. actex:: ex_2_11
.. disqus::
:shortname: interactivepython
:identifier: q11disqus

#. Write a program that will convert degrees fahrenheit to degrees celsius.

Expand Down
29 changes: 0 additions & 29 deletions source/_static/bookfuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,35 +301,6 @@ function loadEditor(data, status, whatever) {
// need to get the divId back with the result...
}

function createOddActiveCode(divid,suppliedSource,sid) {
/* Create 3 tabs for this exercise: an editor, containing a normal activecode block,
an Answer tab, containing an answer provided by the author, and a discussion tab
containing a Disqus commenting/discussion block specific to this exercise.
*/

// #divid will hold all 3 tabs
tabDiv = $("#"+divid);

// create the 3 tabs
tabList = tabDiv.append("<ul></ul>").find("ul");
tabList.append("<li><a href='#" + divid + "-editor'><span>Editor</span></a></li>");
tabList.append("<li><a href='#" + divid + "-answer'><span>Answer</span></a></li>");
tabList.append("<li><a href='#" + divid + "-discussion'><span>Discussion</span></a></li>");

// create the 3 divs corresponding to the 3 tabs
tabDiv.append("<div id='" + divid + "-editor'>Editor</div>");
tabDiv.append("<div id='" + divid + "-answer'>Answer</div>");
tabDiv.append("<div id='" + divid + "-discussion'>Discussion</div>");

// insert the activecode editor in the editor tab
createActiveCode(divid + '-editor', suppliedSource, sid)

// init the jQuery tabs plugin
$(function() {
$( "#"+divid ).tabs();
});

}

function createActiveCode(divid,suppliedSource,sid) {
var eNode;
Expand Down
2 changes: 1 addition & 1 deletion thinkcspy/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.mathjax','luther.sphinx.video','luther.sphinx.codelens','luther.sphinx.activecode', 'luther.sphinx.assess', 'luther.sphinx.animation','luther.sphinx.meta', 'gatech.parsons']
extensions = ['sphinx.ext.mathjax','luther.sphinx.disqus','luther.sphinx.video','luther.sphinx.codelens','luther.sphinx.activecode','luther.sphinx.tabbedStuff', 'luther.sphinx.assess', 'luther.sphinx.animation','luther.sphinx.meta', 'gatech.parsons']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['../source/_templates']
Expand Down

0 comments on commit c87235a

Please sign in to comment.