This commit is contained in:
louiscklaw
2025-01-31 21:15:04 +08:00
parent 3337cc3d1e
commit acf9d862ff
324 changed files with 43162 additions and 0 deletions

45
max015/T05/2a.drawio Normal file
View File

@@ -0,0 +1,45 @@
<mxfile host="65bd71144e">
<diagram id="x3mvl7MIxiUfgaiuTItL" name="Page-1">
<mxGraphModel dx="533" dy="574" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="4" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;" parent="1" source="2" target="3" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="2" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;font-size: 12px;&quot;&gt;initialize&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;&quot; size=&quot;3&quot;&gt;sales = [100, 200, 100, 200, 300, 400]&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="120" width="288" height="60" as="geometry"/>
</mxCell>
<mxCell id="6" value="True" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=12;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="3" target="5" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="9" value="&lt;font&gt;False&lt;/font&gt;" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fontFamily=Helvetica;fontSize=12;strokeColor=#1A1A1A;fontColor=#1A1A1A;labelBackgroundColor=none;" parent="1" source="3" target="8" edge="1">
<mxGeometry x="-0.1748" y="-10" relative="1" as="geometry">
<Array as="points">
<mxPoint x="209" y="300"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="3" value="sales[i] &amp;gt;= 0 ?" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363" y="260" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="7" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontFamily=Helvetica;fontSize=12;entryX=1;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;" parent="1" source="5" target="3" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="710" y="450.28571428571445" as="targetPoint"/>
<Array as="points">
<mxPoint x="670" y="450"/>
<mxPoint x="670" y="300"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="5" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;inventory = inventory - sales[i]&lt;/div&gt;&lt;div style=&quot;&quot;&gt;i = i + 1&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="326" y="420" width="198" height="60" as="geometry"/>
</mxCell>
<mxCell id="8" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font style=&quot;&quot; color=&quot;#1a1a1a&quot;&gt;print inventory left&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;" parent="1" vertex="1">
<mxGeometry x="110" y="420" width="198" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

108
max015/T05/2b.drawio Normal file
View File

@@ -0,0 +1,108 @@
<mxfile host="65bd71144e">
<diagram id="x3mvl7MIxiUfgaiuTItL" name="Page-1">
<mxGraphModel dx="950" dy="1232" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="10" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;font-size: 12px;&quot;&gt;initialize&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;div&gt;sales = [100, 200, 100, 200, 300, 400, -1]&lt;/div&gt;&lt;div&gt;i = 0&lt;/div&gt;&lt;div&gt;inventory = 1000&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281.5" y="-370" width="288" height="130" as="geometry"/>
</mxCell>
<mxCell id="11" value="sales[i] &amp;gt;= 0 ?" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363" y="-160" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="13" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;" parent="1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="424.64" y="-240" as="sourcePoint"/>
<mxPoint x="425.14" y="-160" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="14" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;inventory = inventory - sales[i]&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="326" y="-30" width="198" height="60" as="geometry"/>
</mxCell>
<mxCell id="17" value="inventory &amp;lt; 0" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="362.5" y="100" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;" parent="1" source="14" target="17" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="435.5" y="-70" as="sourcePoint"/>
<mxPoint x="435.0000000000001" y="-20" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="19" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;i = i + 1&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="580" y="110" width="86" height="60" as="geometry"/>
</mxCell>
<mxCell id="20" value="True" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="17" edge="1">
<mxGeometry x="-0.856" y="-10" relative="1" as="geometry">
<mxPoint x="424.81" y="180" as="sourcePoint"/>
<mxPoint x="310" y="-120" as="targetPoint"/>
<Array as="points">
<mxPoint x="310" y="140"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="23" value="False" style="edgeStyle=none;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" target="19" edge="1">
<mxGeometry x="-0.1111" y="10" relative="1" as="geometry">
<mxPoint x="490" y="140" as="sourcePoint"/>
<mxPoint x="434.81000000000006" y="260" as="targetPoint"/>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="24" value="" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="19" target="11" edge="1">
<mxGeometry x="0.1429" y="15" relative="1" as="geometry">
<mxPoint x="500" y="150" as="sourcePoint"/>
<mxPoint x="590" y="150" as="targetPoint"/>
<mxPoint as="offset"/>
<Array as="points">
<mxPoint x="740" y="140"/>
<mxPoint x="740" y="-120"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="25" value="inventory &amp;gt;= 0" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="185" y="-50" width="100" height="80" as="geometry"/>
</mxCell>
<mxCell id="26" value="False" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="11" target="25" edge="1">
<mxGeometry x="0.1429" y="15" relative="1" as="geometry">
<mxPoint x="434.80999999999995" y="190" as="sourcePoint"/>
<mxPoint x="434.80999999999995" y="260" as="targetPoint"/>
<mxPoint as="offset"/>
<Array as="points">
<mxPoint x="235" y="-120"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="27" value="True" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="11" target="14" edge="1">
<mxGeometry x="0.1429" y="15" relative="1" as="geometry">
<mxPoint x="434.80999999999995" y="190" as="sourcePoint"/>
<mxPoint x="434.80999999999995" y="260" as="targetPoint"/>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="28" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;print inventory left&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="50" y="110" width="110" height="60" as="geometry"/>
</mxCell>
<mxCell id="29" value="True" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="25" edge="1">
<mxGeometry x="0.1429" y="15" relative="1" as="geometry">
<mxPoint x="104.57999999999993" y="40" as="sourcePoint"/>
<mxPoint x="104.57999999999993" y="110" as="targetPoint"/>
<mxPoint as="offset"/>
<Array as="points">
<mxPoint x="105" y="-10"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="30" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;print&lt;/div&gt;&lt;div style=&quot;&quot;&gt;out of stock&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="180" y="110" width="110" height="60" as="geometry"/>
</mxCell>
<mxCell id="31" value="False" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" target="30" edge="1">
<mxGeometry x="0.1429" y="15" relative="1" as="geometry">
<mxPoint x="234.6599999999999" y="30" as="sourcePoint"/>
<mxPoint x="234.6599999999999" y="100" as="targetPoint"/>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

73
max015/T05/3a.drawio Normal file
View File

@@ -0,0 +1,73 @@
<mxfile host="65bd71144e">
<diagram id="x3mvl7MIxiUfgaiuTItL" name="Page-1">
<mxGraphModel dx="1900" dy="2464" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="42" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" parent="1" source="10" target="33" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="10" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;loop through every sale in sales list,&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;get item &quot;sale&quot;&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="-450" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="43" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" parent="1" source="32" target="10" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="32" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;font-size: 12px;&quot;&gt;initialize&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;div&gt;sales = [100, 200, 100, 200, 300, 400, -1]&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: initial;&quot;&gt;inventory = 1000&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="-620" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="41" value="False" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="33" target="34" edge="1">
<mxGeometry x="-0.3343" y="25" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="45" value="True" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="33" target="36" edge="1">
<mxGeometry x="-0.003" y="20" relative="1" as="geometry">
<Array as="points">
<mxPoint x="580" y="-260"/>
<mxPoint x="580" y="50"/>
<mxPoint x="520" y="50"/>
<mxPoint x="456" y="50"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="33" value="end of list" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363" y="-300" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="40" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" parent="1" source="34" target="35" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="34" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;inventory = inventory - sales[i]&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="326" y="-160" width="198" height="60" as="geometry"/>
</mxCell>
<mxCell id="38" value="True" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;fontColor=#1A1A1A;labelBackgroundColor=none;" parent="1" source="35" target="36" edge="1">
<mxGeometry x="0.2" y="14" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="44" value="False" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" parent="1" source="35" target="10" edge="1">
<mxGeometry x="-0.0049" y="-20" relative="1" as="geometry">
<Array as="points">
<mxPoint x="220"/>
<mxPoint x="220" y="-405"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="35" value="inventory &amp;lt; 0" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363" y="-40" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="39" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" parent="1" source="36" target="37" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="36" value="print inventory left" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363.75" y="90" width="123.5" height="50" as="geometry"/>
</mxCell>
<mxCell id="37" value="end" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="363.75" y="190" width="123.5" height="50" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

72
max015/T05/3b.drawio Normal file
View File

@@ -0,0 +1,72 @@
<mxfile host="65bd71144e">
<diagram id="x3mvl7MIxiUfgaiuTItL" name="Page-1">
<mxGraphModel dx="1900" dy="2464" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="42" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" edge="1" parent="1" source="10" target="33">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="10" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;loop through every sale in sales list,&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;get item &quot;sale&quot;&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="-450" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="43" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" edge="1" parent="1" source="32" target="10">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="32" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;font-size: 12px;&quot;&gt;initialize&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;div&gt;sales = [100, 200, 100, 200, 300, 400, -1]&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: initial;&quot;&gt;inventory = 1000&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="281" y="-620" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="41" value="False" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" edge="1" parent="1" source="33" target="34">
<mxGeometry x="-0.3343" y="25" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="45" value="True" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" edge="1" parent="1" source="33" target="37">
<mxGeometry x="-0.003" y="20" relative="1" as="geometry">
<Array as="points">
<mxPoint x="580" y="-260"/>
<mxPoint x="580" y="170"/>
<mxPoint x="456" y="170"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="33" value="end of list" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="363" y="-300" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="40" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" edge="1" parent="1" source="34" target="35">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="34" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;inventory = inventory - sales[i]&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="326" y="-160" width="198" height="60" as="geometry"/>
</mxCell>
<mxCell id="38" value="True" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;fontColor=#1A1A1A;labelBackgroundColor=none;" edge="1" parent="1" source="35" target="36">
<mxGeometry x="0.2" y="14" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="44" value="False" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" edge="1" parent="1" source="35" target="10">
<mxGeometry x="-0.0049" y="-20" relative="1" as="geometry">
<Array as="points">
<mxPoint x="220"/>
<mxPoint x="220" y="-405"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="35" value="inventory &amp;lt; 0" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="363" y="-40" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="39" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" edge="1" parent="1" source="36" target="37">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="36" value="print out of stock" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="363.75" y="90" width="123.5" height="50" as="geometry"/>
</mxCell>
<mxCell id="37" value="end" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="363.75" y="190" width="123.5" height="50" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

67
max015/T05/3c.drawio Normal file
View File

@@ -0,0 +1,67 @@
<mxfile host="65bd71144e">
<diagram id="x3mvl7MIxiUfgaiuTItL" name="Page-1">
<mxGraphModel dx="1346" dy="1840" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="49" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#1A1A1A;fontColor=#1A1A1A;" edge="1" parent="1" source="10" target="46">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="10" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;loop through every sale in sales list,&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;get item &quot;sale&quot; (denoted 's')&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="-450" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="43" value="" style="edgeStyle=none;html=1;strokeColor=#1A1A1A;" parent="1" source="32" target="10" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="32" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot; style=&quot;font-size: 12px;&quot;&gt;initialize&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;div&gt;sales = [100, 200, None, 100, 200, 300, 400, None]&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: initial;&quot;&gt;inventory = 1000&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" parent="1" vertex="1">
<mxGeometry x="281" y="-600" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="48" value="True" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#1A1A1A;labelBackgroundColor=none;fontColor=#1A1A1A;" edge="1" parent="1" source="46" target="10">
<mxGeometry x="0.0172" y="20" relative="1" as="geometry">
<Array as="points">
<mxPoint x="640" y="-250"/>
<mxPoint x="640" y="-405"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="51" value="False" style="edgeStyle=none;html=1;labelBackgroundColor=none;strokeColor=#1A1A1A;fontColor=#1A1A1A;" edge="1" parent="1" source="46" target="50">
<mxGeometry y="15" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="46" value="s == None ?" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="362.5" y="-290" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="53" value="" style="edgeStyle=none;html=1;labelBackgroundColor=none;strokeColor=#1A1A1A;fontColor=#1A1A1A;" edge="1" parent="1" source="50" target="52">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="50" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;inventory = inventory - s&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="281" y="-170" width="288" height="90" as="geometry"/>
</mxCell>
<mxCell id="55" value="False" style="edgeStyle=none;html=1;labelBackgroundColor=none;strokeColor=#1A1A1A;fontColor=#1A1A1A;" edge="1" parent="1" source="52" target="54">
<mxGeometry y="15" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="58" value="True" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#1A1A1A;fontColor=#1A1A1A;" edge="1" parent="1" source="52" target="56">
<mxGeometry x="-0.2537" y="10" relative="1" as="geometry">
<Array as="points">
<mxPoint x="575"/>
</Array>
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="52" value="inventory &amp;lt; 0 ?" style="rhombus;whiteSpace=wrap;html=1;strokeColor=#1A1A1A;fillColor=#E6E6E6;fontColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="362.5" y="-40" width="125" height="80" as="geometry"/>
</mxCell>
<mxCell id="54" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;print &quot;out of stock&quot;&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="370" y="80" width="110" height="90" as="geometry"/>
</mxCell>
<mxCell id="56" value="&lt;div style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;font color=&quot;#1a1a1a&quot;&gt;end&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;background-color: rgb(30, 30, 30); font-size: 18px; font-family: &amp;quot;Monaco for Powerline&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace, Consolas, &amp;quot;Courier New&amp;quot;, monospace;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E6E6E6;fontColor=#050505;strokeColor=#1A1A1A;" vertex="1" parent="1">
<mxGeometry x="520" y="80" width="110" height="90" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@@ -0,0 +1,914 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CDS1001 Tutorial 5 Report"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Input your name and student ID in the cell below (<font color='red'>if a cell is not in edit mode, double click it</font>):"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-info\">\n",
" \n",
"Your name: \n",
"\n",
"Your student ID:\n",
" \n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Objectives:\n",
"- Understand why loops are used in coding\n",
"- Be able to understand and use while loop and for loop\n",
"- Be able to understand and apply the basic pattens of loops\n",
"- Be able to understand and draw flow charts for loops\n",
"- Be able to use print() in debugging"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### **Instructions for the report**:\n",
"* Follow Section 1 and Section 2 of the tutorial instruction to launch Python IDLE through Anaconda Navigation.\n",
"* Refer to Section 2.2 of the tutorial instruction to open tutorial 5 report\n",
"* Complete Parts 1-5 led by the lecturer\n",
"* Complete Part 6 independently\n",
"* Follow Section 3 of the tutorial instruction to save the report and zip the report folder. The zip file is named as CDS1001T5Report{your student_id}.zip (e.g., if student_id is 1234567, then the zip file's name is CDS1001T5Report1234567.zip). <font color='red'>The zip file needs to include the following files:\n",
" - an .ipynb file of this tutorial report \n",
" - image files of flowcharts or screenshots used in this tutorial report </font> \n",
"* Submit the zip file of the report folder to the Moodle. The submission due date is **<font color='red'>24 Oct 2023 11:55 PM</font>**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 1 Loop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.1. Read and execute the following code, and answer the questions below:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the city you are from: Hong Kong\n",
"Enter the city you are from: Shanghai\n",
"Enter the city you are from: Tokyo\n",
"Enter the city you are from: Hong Kong\n",
"Enter the city you are from: end\n",
"Number of guests from Hong Kong: 2\n"
]
}
],
"source": [
"number_hk = 0\n",
"flag_end = False\n",
"while not flag_end:\n",
" city = input('Enter the city that the guest comes from: ')\n",
" if city == 'Hong Kong':\n",
" number_hk = number_hk +1\n",
" elif city == 'End' or city == 'end':\n",
" flag_end = True\n",
"print('Number of guests from Hong Kong:', number_hk)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 1.1.1: What is the body of the loop used in the code above? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Answer:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 1.1.2: What's the condition for the loop to stop? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 1.1.3: What does the loop of the above code do? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 1.1.4: Is it possible to rewrite the code above without using loops but using repeated codes? Explain your reasons. (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 2 while Loop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.1. Execute the codes below, explain how the codes are executed, and draw the flowcharts. (4 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (a)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory left: -300\n"
]
}
],
"source": [
"sales = [100, 200, 100, 200, 300, 400, -1]\n",
"i = 0\n",
"inventory = 1000\n",
"while sales[i]>=0: #sales[i] indicates the (i+1)-th item of the sequence sales\n",
" inventory = inventory - sales[i]\n",
" i = i + 1\n",
"print('Inventory left:', inventory)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how the above code is executed </font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to insert a figure of the flowchart of the code above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (b)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Out of stock!\n"
]
}
],
"source": [
"sales = [100, 200, 100, 200, 300, 400, -1]\n",
"i = 0\n",
"inventory = 1000\n",
"while sales[i]>=0: #sales[i] indicates the (i+1)-th item of the sequence sales\n",
" inventory = inventory - sales[i]\n",
" if inventory < 0:\n",
" break\n",
" i = i + 1\n",
"if inventory >= 0:\n",
" print('Inventory left:', inventory)\n",
"else:\n",
" print('Out of stock!')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how the above code is executed </font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to insert a figure of the flowchart of the code above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.2. Execute the code below, explain the errors received, and discuss how to fix the errors (4 points):"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (a)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"ename": "IndentationError",
"evalue": "expected an indented block (<ipython-input-12-a14b33f59865>, line 4)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-12-a14b33f59865>\"\u001b[0;36m, line \u001b[0;32m4\u001b[0m\n\u001b[0;31m total = total + i\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n"
]
}
],
"source": [
"total = 0\n",
"i = 1\n",
"while i<=100:\n",
"total = total + i\n",
"i = i + 1\n",
"print(total)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain what are the errors and how to fix them </font>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Edit this cell to write the correct code:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (b)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-6-4110f0b7133b>, line 4)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-6-4110f0b7133b>\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m while flag=0:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"total = 0\n",
"flag = 0\n",
"i = 1\n",
"while flag=0:\n",
" total = total + i\n",
" i = i + 1\n",
" if i > 100:\n",
" flag = 1\n",
"print(total)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain what are the errors and how to fix them </font>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Edit this cell to write the correct code:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.3. Write a code for the flow chart below using a while loop, and explain the code: (4 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src = \"flow0.png\" width=\"400\">"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"#edit this cell to write the code for the flowchart above"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain what the above code does:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 3 for Loop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3.1. Execute the codes below, explain how the codes are executed, and draw the flowcharts: (6 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (a)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory left: -300\n"
]
}
],
"source": [
"sales = [100, 200, 100, 200, 300, 400]\n",
"inventory = 1000\n",
"for s in sales:\n",
" inventory = inventory - s \n",
"print('Inventory left:', inventory)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how the above code is executed </font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to insert a figure of the flowchart of the code above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (b)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Out of stock!\n"
]
}
],
"source": [
"sales = [100, 200, 100, 200, 300, 400]\n",
"inventory = 1000\n",
"for s in sales:\n",
" inventory = inventory - s\n",
" if inventory<0:\n",
" print('Out of stock!')\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how the above code is executed </font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to insert a figure of the flowchart of the code above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### (c)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Out of stock!\n"
]
}
],
"source": [
"sales = [100, 200, None, 100, 200, 300, 400, None] \n",
"inventory = 1000\n",
"for s in sales:\n",
" if s == None:\n",
" continue\n",
" inventory = inventory - s\n",
" if inventory<0:\n",
" print('Out of stock!')\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how the above code is executed </font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to insert a figure of the flowchart of the code above</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3.2. Write a code for the flow chart below, using for loop, and explain the code. (4 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src = \"flow1.png\" width=\"400\">"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"#edit this cell to write the code for the flowchart above"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain what the above code does:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 4 Loop Patterns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4.1. Vote\n",
"Your department has a poll on the location to celebrate the new year, among three candidates, including 'Hong Kong Disney Land Hotel', \"Hotel ICON', and \"Hong Kong Ocean Park Marriott Hotel\". Please write a program to enter each colleague's choice, and output the poll result.\n",
"\n",
"Sample Input/Output\n",
"\n",
" Enter Your Choice (0-Exit Poll, 1-Disney, 2-Hotel ICON, 3-Ocean Park): 1\n",
" Enter Your Choice (0-Exit Poll, 1-Disney, 2-Hotel ICON, 3-Ocean Park): 2\n",
" Enter Your Choice (0-Exit Poll, 1-Disney, 2-Hotel ICON, 3-Ocean Park): 2\n",
" Enter Your Choice (0-Exit Poll, 1-Disney, 2-Hotel ICON, 3-Ocean Park): 3\n",
" Enter Your Choice (0-Exit Poll, 1-Disney, 2-Hotel ICON, 3-Ocean Park): 0\n",
" \n",
" Disney: 1\n",
" Hotel ICON: 2\n",
" Ocean Park: 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 4.1.1: How are you going to define variables to store votes for three different candidate locations? What are their names and types? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 4.1.2: Are you going to use a while loop or a for loop to write the code? Why and how?(2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 4.1.3: Write codes. (6 points)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#edit this cell to write the program"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 4.1.4: Are there any other ways to write the code? For example, is it possible to use an infinite loop with break, or use a flag variable, etc? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#edit this cell to show other possible ways to write the code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 5 Debugging"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 5.1. Execute the code below, and use the information printed to identify the error and fix it"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"max of data is: 5\n",
"sum of data is: 21\n",
"min of data is: 1\n"
]
}
],
"source": [
"data = [1,4,2,5,4]\n",
"result = 0\n",
"for entry in data:\n",
" if entry>result:\n",
" result = entry\n",
"print('max of data is:', result)\n",
"for entry in data:\n",
" result = result + entry\n",
"print('sum of data is:', result)\n",
"for entry in data:\n",
" if entry<result:\n",
" result = entry\n",
"print('min of data is:', result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 5.1.1. Execute the code above, and describe which output information is not correct. (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 5.1.2. From the wrong output information identified, can you tell which part of the code may have problems? (2 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Question 5.1.3. Describe the problem of the code, and explain how to correct it. (4 points)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to answer the question above:</font>"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#Edit this cell to write the corrected code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>*Create a python file of the code above in Python IDLE, execute the code for a test, and paste the screenshot of the test result below in this cell:*</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 6 Other Exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 6.1. Cheapest Carrier (25 points)\n",
"Use a while loop to write a program that prompts a logistics manager to enter shipping rates submitted by carriers until the manager enters 'quit'. The program then outputs the lowest shipping rate, and the carrier who submits the lowest shipping rate.\n",
"\n",
"Sample Input/Output\n",
"\n",
" Enter Carrier Name: OOCL\n",
" Enter Shipping Rate: 130\n",
" Enter Carrier Name: MMM\n",
" Enter Shipping Rate: 100\n",
" Enter Carrier Name: NNN\n",
" Enter Shipping Rate: 110\n",
" Enter Carrier Name: quit\n",
" \n",
" The lowest shipping rate is 100, submitted by MMM."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#edit this cell to write your code\n",
"#Hint: (1) define variables to store the lowest shipping rate, and the carrier who submits the lowest shipping rate. \n",
"# (2) update these variables in each iteration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Execute and test your revised code above for various inputs. Edit this cell to copy your test results below:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how you use iterations to write the code:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 6.2. Sales Forecast (25 points)\n",
"\n",
"Given the actual sales in the past year as follows, a sales manager predicts sales for the new year in the following way:\n",
"\n",
"For the i-th month of the new year, its forecasted sales = the actual sales of the i-th month of the past year * 1.2 if i is not 6 or 7; otherwise, its forecasted sales = the actual sales of the i-th month of the past year * 1.3\n",
"\n",
"Use a for loop to revise the code below, so as to output the sales forecast for the 12 months of the new year"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Actual Sales of month 1 in the past year: 100\n",
"Actual Sales of month 2 in the past year: 120\n",
"Actual Sales of month 3 in the past year: 100\n",
"Actual Sales of month 4 in the past year: 120\n",
"Actual Sales of month 5 in the past year: 140\n",
"Actual Sales of month 6 in the past year: 130\n",
"Actual Sales of month 7 in the past year: 120\n",
"Actual Sales of month 8 in the past year: 150\n",
"Actual Sales of month 9 in the past year: 150\n",
"Actual Sales of month 10 in the past year: 110\n",
"Actual Sales of month 11 in the past year: 120\n",
"Actual Sales of month 12 in the past year: 100\n"
]
}
],
"source": [
"#the actual sales of the 12 months of the past year are stored in the list actual_sales_past:\n",
"actual_sales_past = [100,120,100,120,140,130,120,150,150,110,120,100]\n",
"#the actual sales of the i-th month of the past year is stored in actual_sales_past[i-1] for i =1,2,...,12\n",
"#the for loop below is to print the actual sales for the 12 months of the past years:\n",
"for i in [1,2,3,4,5,6,7,8,9,10,11,12]:\n",
" print('Actual Sales of month', i, 'in the past year:', actual_sales_past[i-1])\n",
"\n",
"#Based on the code above and the rule mentioned in the problem description, \n",
"#write a new code below to compute and output the sales forcast for the 12 months of the new year: \n",
"\n",
"#Hints:(1) use a for loop to iteratate data entry in actual_sales_past; \n",
"# (2) use a variable i to indicate the month id to be processed in the iteartion;\n",
"# (3) compute the forecasted sales for month i based on the actual sales of the i-th month of the past year, \n",
"# which is stored in actual_sales_past[i-1] for i = 1,2,...,12\n",
"# (4) print the forecasted sales for month i\n",
"# (5) update variable i"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Execute and test your revised code above for various inputs. Edit this cell to copy your test results below:</font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color='red'>Edit this cell to explain how you use iterations to write the code:</font>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

BIN
max015/T05/flow0.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
max015/T05/flow1.png (Stored with Git LFS) Normal file

Binary file not shown.

13
max015/T05/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "t05",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gitUpdate":"git add . && git commit -m\"update max015\""
},
"keywords": [],
"author": "",
"license": "ISC"
}