-
Notifications
You must be signed in to change notification settings - Fork 0
The `pl faded parsons` element
Nelson Lojo edited this page May 3, 2023
·
9 revisions
A pl-faded-parsons
element presents the student with a chunk of code
in which the lines are scrambled and must be placed in the correct
order (Parsons problem). Some lines may also have blanks substituted for variable
names, keywords, etc. (hence Faded Parsons).
The instructor provides the reference solution, information regarding what to "fade" and by how much, and one or more tests that are run to evaluate the student's answer.
- Provided code lines
- Provided as either (1) the only text in the
<pl-faded-parsons>
element, (2) under the<code-lines
child element to<pl-faded-parsons>
, or (3) incode_lines.py
under theserverFilesQuestion/
sub-directory of the question. - This should be the code that will be scrambled and shown to the student,
including
!BLANK
wherever a blank should occur (so technically these lines are not valid Python/Ruby). Order doesn't matter. - If a line has a comment of the form
#0given
, this means that that line should pre-populate the "solution" box at indent level zero (no indent; subsequent indent levels are 1, 2, etc.)
- Provided as either (1) the only text in the
- The solution must be provided in
solution
(no extension) directly under the question directory. This can be rendered, as part of apl-answer-panel
(this is the default behavior) or similar feedback mechanism.- You can additionally provide comments/notes in Markdown to be shown along
with the reference solution in
solution_notes.md
- You can additionally provide comments/notes in Markdown to be shown along
with the reference solution in
Attribute | Type | Default | Possible Values | Description |
---|---|---|---|---|
language |
string | "py" | "py", "ruby" | Language the problem is in, given as the filename extension for files in that language. If format="bottom" is specified, this determines what syntax highlighting to apply to the text in pre-text and post-text . |
format |
string | "right" | "right", "bottom", "no-code" | Specifies where the submission box for lines is placed relative to the source tray. If no-code is specified, the source tray is hidden and the lines are put into the submission box. If using bottom or no-code , the pre-text and post-text sub-fields may be provided as child elements of pl-faded-parsons to precede or succeed the submission box with formatted code. If you use either of these fields, the lines scrambled to the student must be in a child element called code-lines (see below example) or in code_lines.py (see "Provided code lines" above). |
line-order |
string | "alpha" | "alpha", "random", "fixed" | How to display the lines of code to the student: alpha (alphabetical order), fixed (in the order they are provided), or random . |
partial-credit |
boolean | false | "false", "true" | Whether to give partial credit; see below. |
answers-name |
string | "fp" | any string
|
Name of answers dict, only matters if >1 Faded Parsons element in same question |
TBD: replace this with a screenshot of the element in action; the png
file should eventually go in PrairieLearn:PrairieLearn/docs/elements/pl-faded-parsons.png
Horizontal format:
<pl-question-panel>
The problem prompt and description of the question goes here.
</pl-question-panel>
<pl-faded-parsons>
You can put additional text here if you like, but the actual Parsons
code boxes etc will be rendered automatically.
</pl-faded-parsons>
Vertical format:
<pl-question-panel>
The problem prompt and description of the question goes here.
</pl-question-panel>
<pl-faded-parsons format="bottom">
<pre-text>
Any text to preface the submission box
</pre-text>
<code-lines>
Lines that the student can use to construct their solution
</code-lines>
<post-text>
Any text to succeed the submission box
</post-text>
</pl-faded-parsons>
<pl-question-panel>
<markdown>
# Add and validate a field on the RottenPotatoes Movie model
...
</markdown>
</pl-question-panel>
<pl-faded-parsons language="ruby">
class Movie < ActiveRecord::Base
validate :rating_consistent_with_date
def !BLANK()
pg13_invented = Time.parse "1 Jan 1984"
if (!BLANK) and (!BLANK)
!BLANK.errors.add(:rating, 'only valid for 1984 and later')
end
end
end
</pl-faded-parsons>
<pl-question-panel>
<markdown>
# Implement some of the `Customer` class
...
</pl-question-panel>
<pl-faded-parsons format="bottom" language="ruby">
<pre-text>
class GiftCard
attr_reader :balance, :error
def initialize(balance)
if balance < 0
raise ArgumentError.new("New gift card cannot have negative balance")
end
@balance = balance
@error = nil
end
def withdraw(amount)
if @balance >= amount
@balance -= amount
else
@error = "Insufficient balance"
return nil
end
end
end
</pre-text>
<code-lines>
class Customer
attr_accessor :name, :gift_card
def initialize(name, gift_card=nil)
@gift_card = gift_card
@name = name
end
def pay(amount)
if gift_card.withdraw(amount)
self.notify("payment successful")
else
self.notify("purchase cannot be completed")
end
end
end
</code-lines>
</pl-faded-parsons>
<pl-question-panel>
<h1>Write a test for the partially implemented Customer class</h1>
</pl-question-panel>
<pl-faded-parsons format="no-code" language="ruby">
<pre-text>
describe Customer do
it 'notifies the customer of a successful payment' do
</pre-text>
<code-lines>
@loaded_gift_card = double('gift_card') #0given
allow(@loaded_gift_card).to receive(:!BLANK).and_return(true)
@customer = !BLANK.new('Student', @loaded_gift_card)
expect(!BLANK).to receive(:!BLANK).with("payment successful")
@customer.!BLANK(10)
</code-lines>
<post-text>
end
end
</post-text>
</pl-faded-parsons>