update,
This commit is contained in:
73
max015/T06/Question 3.1.3.drawio
Normal file
73
max015/T06/Question 3.1.3.drawio
Normal file
@@ -0,0 +1,73 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="IsahtfXpGEnurlJZm06P" name="Page-1">
|
||||
<mxGraphModel dx="1085" dy="1014" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="15" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="2" target="5">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="2" value="<div style="line-height: 24px;"><font><span style="font-size: 18px;">open file request.txt, assign it to file_handler input_file</span></font><br></div>" style="whiteSpace=wrap;html=1;labelBackgroundColor=default;fontColor=#000000;" parent="1" vertex="1">
|
||||
<mxGeometry x="110" y="60" width="380" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="16" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="5" target="7">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="<div style="line-height: 24px;"><font><span style="font-size: 18px;">open file new_request.txt, assign it to file_handler output_file</span></font><br></div>" style="whiteSpace=wrap;html=1;fontFamily=Helvetica;strokeColor=default;fillColor=none;align=center;labelBackgroundColor=default;fontColor=#3b3535;" parent="1" vertex="1">
|
||||
<mxGeometry x="110" y="190" width="380" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="17" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="7" target="9">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="23" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;fontColor=#000000;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="7" target="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="50" y="370.1111111111111" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="100" y="370"/>
|
||||
<mxPoint x="100" y="620"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="7" value="if the line started with APPLE" style="rhombus;whiteSpace=wrap;html=1;fontSize=18;" parent="1" vertex="1">
|
||||
<mxGeometry x="153.75" y="310" width="292.5" height="120" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="18" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="9" target="10">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="<font style="font-size: 18px;">print it out without new line ending&nbsp;<br>write it to the output_file<br></font>" style="whiteSpace=wrap;html=1;fontFamily=Helvetica;" parent="1" vertex="1">
|
||||
<mxGeometry x="135" y="480" width="330" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="19" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="10" target="14">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="10" value="<font style="font-size: 18px;">next line</font>" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="160" y="590" width="280" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="21" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="11" target="13">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="11" value="close the output_file handler" style="whiteSpace=wrap;html=1;fontSize=18;" parent="1" vertex="1">
|
||||
<mxGeometry x="160" y="820" width="280" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="13" value="close the input_file handler" style="whiteSpace=wrap;html=1;fontSize=18;" parent="1" vertex="1">
|
||||
<mxGeometry x="160" y="930" width="280" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="20" value="" style="edgeStyle=none;html=1;fontColor=#000000;" edge="1" parent="1" source="14" target="11">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="22" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontColor=#000000;" edge="1" parent="1" source="14">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="300" y="280" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="740"/>
|
||||
<mxPoint x="560" y="280"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="14" value="reach the <br>end of file ?" style="rhombus;whiteSpace=wrap;html=1;fontSize=18;" parent="1" vertex="1">
|
||||
<mxGeometry x="192.5" y="700" width="215" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
max015/T06/T06/3.1.3.png
(Stored with Git LFS)
Normal file
BIN
max015/T06/T06/3.1.3.png
(Stored with Git LFS)
Normal file
Binary file not shown.
25
max015/T06/T06/4_1_6.py
Normal file
25
max015/T06/T06/4_1_6.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#edit this cell to write the program
|
||||
|
||||
votes_file = open ('./report/votes.txt', 'r')
|
||||
results_file = open ('./report/results.txt', 'w')
|
||||
disney_vote = 0
|
||||
hotel_icon_vote = 0
|
||||
ocean_park_vote = 0
|
||||
|
||||
for s in votes_file:
|
||||
if s.strip() == 'Disney':
|
||||
disney_vote = disney_vote + 1
|
||||
if s.strip() == 'Hotel ICON' :
|
||||
hotel_icon_vote = hotel_icon_vote + 1
|
||||
if s.strip() == 'Ocean Park':
|
||||
ocean_park_vote = ocean_park_vote + 1
|
||||
|
||||
disney_output = 'Disney:%s\n' % disney_vote
|
||||
hotel_icon_output = 'Hotel ICON:%s\n' % hotel_icon_vote
|
||||
ocean_park_output = 'Ocean Park:%s\n' % ocean_park_vote
|
||||
output = disney_output + hotel_icon_output + ocean_park_output
|
||||
|
||||
results_file.write(output.strip())
|
||||
|
||||
results_file.close()
|
||||
votes_file.close()
|
24
max015/T06/T06/5_1_5.py
Normal file
24
max015/T06/T06/5_1_5.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#edit this cell to write your code
|
||||
#Hint: (1) input the name of the input file
|
||||
# (2) define a file handle for the input file
|
||||
# (3) for each line of the file, extract the carrier id and shipping rate by using string's find function
|
||||
# and slice operation, and then update the variables that store the lowest shipping rate and its carrier id
|
||||
|
||||
lowest_rate = -1
|
||||
lowest_rate_carrier = ""
|
||||
|
||||
file_name = input("please enter a file name: ")
|
||||
|
||||
with open(file_name, 'r') as carrier_file:
|
||||
for s in carrier_file:
|
||||
if s != "-1":
|
||||
p = s.find(' ')
|
||||
rate = float(s[p+1:])
|
||||
carrier = s[0:p]
|
||||
if ( rate < lowest_rate or lowest_rate == -1):
|
||||
lowest_rate_carrier = carrier
|
||||
lowest_rate = rate
|
||||
|
||||
output = 'The lowest shipping rate is %s, ' % lowest_rate
|
||||
output1 = 'submitted by %s.' % lowest_rate_carrier
|
||||
print(output+ output1)
|
1712
max015/T06/T06/CDS1001T6Report.ipynb
Normal file
1712
max015/T06/T06/CDS1001T6Report.ipynb
Normal file
File diff suppressed because it is too large
Load Diff
3
max015/T06/T06/new_requests.txt
Normal file
3
max015/T06/T06/new_requests.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
APPLE 100
|
||||
APPLE 120
|
||||
APPLE 130
|
7
max015/T06/T06/report/carrier.txt
Normal file
7
max015/T06/T06/report/carrier.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
OOCL 130
|
||||
MMM 100
|
||||
NNN 110
|
||||
OOO 99
|
||||
PPP 80
|
||||
RRR 111
|
||||
-1
|
3
max015/T06/T06/report/results.txt
Normal file
3
max015/T06/T06/report/results.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Disney:3
|
||||
Hotel ICON:4
|
||||
Ocean Park:3
|
11
max015/T06/T06/report/votes.txt
Normal file
11
max015/T06/T06/report/votes.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
Disney
|
||||
Hotel ICON
|
||||
Hotel ICON
|
||||
Ocean Park
|
||||
Disney
|
||||
Hotel ICON
|
||||
Ocean Park
|
||||
Disney
|
||||
Ocean Park
|
||||
Hotel ICON
|
||||
-1
|
6
max015/T06/T06/requests.txt
Normal file
6
max015/T06/T06/requests.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
APPLE 100
|
||||
ORANGE 90
|
||||
BANANA 95
|
||||
APPLE 120
|
||||
APPLE 130
|
||||
BANANA 2 5
|
Reference in New Issue
Block a user