112 lines
5.6 KiB
XML
112 lines
5.6 KiB
XML
<course>
|
|
<chapter url_name="EmbeddedPythonChapter">
|
|
|
|
<vertical url_name="Homework1">
|
|
<problem url_name="schematic_problem">
|
|
<schematicresponse>
|
|
<center>
|
|
<schematic height="500" width="600" parts="g,n,s" analyses="dc,tran"
|
|
submit_analyses="{"tran":[["Z",0.0000004,0.0000009,0.0000014,0.0000019,0.0000024,0.0000029,0.0000034,0.000039]]}"
|
|
initial_value="[["w",[112,96,128,96]],["w",[256,96,240,96]],["w",[192,96,240,96]],["s",[240,96,0],{"color":"cyan","offset":"","plot offset":"0","_json_":3},["Z"]],["w",[32,224,192,224]],["w",[96,48,192,48]],["L",[256,96,3],{"label":"Z","_json_":6},["Z"]],["r",[192,48,0],{"name":"Rpullup","r":"10K","_json_":7},["1","Z"]],["w",[32,144,32,192]],["w",[32,224,32,192]],["w",[48,192,32,192]],["w",[32,96,32,144]],["w",[48,144,32,144]],["w",[32,48,32,96]],["w",[48,96,32,96]],["w",[32,48,48,48]],["g",[32,224,0],{"_json_":16},["0"]],["v",[96,192,1],{"name":"VC","value":"square(3,0,250K)","_json_":17},["C","0"]],["v",[96,144,1],{"name":"VB","value":"square(3,0,500K)","_json_":18},["B","0"]],["v",[96,96,1],{"name":"VA","value":"square(3,0,1000K)","_json_":19},["A","0"]],["v",[96,48,1],{"name":"Vpwr","value":"dc(3)","_json_":20},["1","0"]],["L",[96,96,2],{"label":"A","_json_":21},["A"]],["w",[96,96,104,96]],["L",[96,144,2],{"label":"B","_json_":23},["B"]],["w",[96,144,104,144]],["L",[96,192,2],{"label":"C","_json_":25},["C"]],["w",[96,192,104,192]],["w",[192,96,192,112]],["s",[112,96,0],{"color":"red","offset":"15","plot offset":"0","_json_":28},["A"]],["w",[104,96,112,96]],["s",[112,144,0],{"color":"green","offset":"10","plot offset":"0","_json_":30},["B"]],["w",[104,144,112,144]],["w",[128,144,112,144]],["s",[112,192,0],{"color":"blue","offset":"5","plot offset":"0","_json_":33},["C"]],["w",[104,192,112,192]],["w",[128,192,112,192]],["view",0,0,2,"5","10","10MEG",null,"100","4us"]]"
|
|
/>
|
|
</center>
|
|
<answer type="loncapa/python">
|
|
# for a schematic response, submission[i] is the json representation
|
|
# of the diagram and analysis results for the i-th schematic tag
|
|
|
|
def get_tran(json,signal):
|
|
for element in json:
|
|
if element[0] == 'transient':
|
|
return element[1].get(signal,[])
|
|
return []
|
|
|
|
def get_value(at,output):
|
|
for (t,v) in output:
|
|
if at == t: return v
|
|
return None
|
|
|
|
output = get_tran(submission[0],'Z')
|
|
okay = True
|
|
|
|
# output should be 1, 1, 1, 1, 1, 0, 0, 0
|
|
if get_value(0.0000004,output) < 2.7: okay = False;
|
|
if get_value(0.0000009,output) < 2.7: okay = False;
|
|
if get_value(0.0000014,output) < 2.7: okay = False;
|
|
if get_value(0.0000019,output) < 2.7: okay = False;
|
|
if get_value(0.0000024,output) < 2.7: okay = False;
|
|
if get_value(0.0000029,output) > 0.25: okay = False;
|
|
if get_value(0.0000034,output) > 0.25: okay = False;
|
|
if get_value(0.0000039,output) > 0.25: okay = False;
|
|
|
|
correct = ['correct' if okay else 'incorrect']
|
|
|
|
</answer></schematicresponse>
|
|
|
|
|
|
|
|
|
|
</problem>
|
|
|
|
|
|
|
|
<problem url_name="cfn_problem">
|
|
<text>
|
|
<script type="text/python" system_path="python_lib">
|
|
def test_csv(expect, ans):
|
|
# Take out all spaces in expected answer
|
|
expect = [i.strip(' ') for i in str(expect).split(',')]
|
|
# Take out all spaces in student solution
|
|
ans = [i.strip(' ') for i in str(ans).split(',')]
|
|
|
|
def strip_q(x):
|
|
# Strip quotes around strings if students have entered them
|
|
stripped_ans = []
|
|
for item in x:
|
|
if item[0] == "'" and item[-1]=="'":
|
|
item = item.strip("'")
|
|
elif item[0] == '"' and item[-1] == '"':
|
|
item = item.strip('"')
|
|
stripped_ans.append(item)
|
|
return stripped_ans
|
|
|
|
return strip_q(expect) == strip_q(ans)
|
|
</script>
|
|
<ol class="enumerate">
|
|
<li>
|
|
<pre>
|
|
num = 0
|
|
while num <= 5:
|
|
print(num)
|
|
num += 1
|
|
|
|
print("Outside of loop")
|
|
print(num)
|
|
</pre>
|
|
<p>
|
|
<customresponse cfn="test_csv" expect="0, 1, 2, 3, 4, 5, 'Outside of loop', 6">
|
|
<textline size="50" correct_answer="0, 1, 2, 3, 4, 5, 'Outside of loop', 6"/>
|
|
</customresponse>
|
|
</p>
|
|
</li>
|
|
</ol>
|
|
</text>
|
|
</problem>
|
|
|
|
<problem url_name="computed_answer">
|
|
|
|
<customresponse>
|
|
<textline size="5" correct_answer="Xyzzy"/>
|
|
<answer type="loncapa/python">
|
|
if submission[0] == "Xyzzy":
|
|
correct = ['correct']
|
|
else:
|
|
correct = ['incorrect']
|
|
</answer>
|
|
</customresponse>
|
|
|
|
</problem>
|
|
|
|
</vertical>
|
|
</chapter>
|
|
</course>
|