-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreject_tasks.html
More file actions
219 lines (181 loc) · 7.26 KB
/
reject_tasks.html
File metadata and controls
219 lines (181 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html>
<html>
<head>
<title>CSSE1001 Tutorial</title>
<link href="tasks/styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>Reject Tasks</h1>
<i>Tasks which have been written up and then thrown out in favour of other tasks.
Throwing them in here in case they end up being useful later.</i>
<h2>Week 2/3 (Intro): Tax Time</h2>
<i>Comment: Didn't have any room to put this task in week 2 or 3, but it's
still a good task.</i>
<p>
The Australian Tax Office applies the following income tax rates based on annual
income:
</p>
<div class="table">
<table>
<thead>
<tr><th>Taxable income</th><th>Tax on this income</th></tr>
</thead>
<tbody>
<tr><td>0 - $6,000</td><td>Nil</td></tr>
<tr><td>$6,001 - $37,000</td><td>15c for each $1 over $6000</td></tr>
<tr><td>$37,001 - $80,000</td><td>$4,650 plus 30c for each $1 over $37,000</td></tr>
<tr><td>$80,001 - $180,000</td><td>$17,550 plus 37c for each $1 over $80,000</td></tr>
<tr><td>$180,001 and over</td><td>$54,550 plus 45c for each $1 over $180,000</td></tr>
</tbody>
</table>
</div>
<p>
Write a function <tt>calculate_tax</tt> which takes an integer representing
the taxable income of a person, and returns the amount of tax to pay (both in
dollars).
</p>
<h2>Week 5: Processing Data in a String</h2>
<i>Comment: Hard to make the task statement understandable; there are other
good tasks to use instead.</i>
<p>
A for loop allows you to iterate over an iterable sequence. This
means that you can construct a loop that will run once for each element in a
sequence (for example, each value in a list or each character in a string).
</p>
<p>
In this task, we are given a string from which we wish to extract every character
before a particular character sequence is encountered.
</p>
<p>
Write a function, <tt><span class="builtin">string_before</span></tt>, which
takes two strings as arguments. The first is the string from which we aim to
extract the characters. The second is the delimiting sequence.
</p>
<div class="important">
<b>Hint:</b>
<p>
A <tt><span class="builtin">break</span></tt> statement can be used to terminate
a while or for loop.
</p>
<p>
A <tt><span class="builtin">continue</span></tt> statement will cause a loop to
immediately move to the next item in the sequence.
</p>
<pre>
<span class="prompt"></span> for item in [1, 2, 3, 4, 5, 6, 7, 8]:
<span class="prompt"></span> if item % 2:
<span class="prompt"></span> continue
<span class="prompt"></span> elif item == 6:
<span class="prompt"></span> break
<span class="prompt"></span> print item
<span class="result"></span> 2
<span class="result"></span> 4
</pre>
</div>
<h2>Week 5: Using Enumerate</h2>
<i>Commment: Not enough room in the tutorial for this exercise.</i>
<p>it is often useful for a <tt><span class="builtin">for</span></tt> loop to
be able to access both the value of some element in a sequence and its index at
the same time. We can do this using the
<tt><span class="builtin">enumerate</span></tt> function.
</p>
<p>
<tt><span class="builtin">enumerate</span></tt> generates a sequence of tuples,
where the first item in the tuple is the index of the current in the sequence
and the second item is its value. A <tt><span class="builtin">for</span></tt>
loop can the iterate over both items at once.
</p>
<div class="important">
<b>Example:</b>
<pre>
<span class="prompt"></span> for index, item in enumerate('abc'):
<span class="prompt"></span> print index, item
<span class="result"></span> 0 a
<span class="result"></span> 1 b
<span class="result"></span> 2 c
</div>
<p>
The message below has been encoded using a very simple scheme: a random letter
has been inserted before every second letter in the original message (starting
with the first letter, ie indexed from 0).
</p>
<pre>
<span class="prompt">>>></span> encode(<span class="string">'Test of encoding function')</span>
<span class="result"></span> 'lTretsxty qocfz aeunrcoomdliknegv zfzuwnfcrtzixotn'
</pre>
<p>
In this task, you will need to write a <tt><span class="builtin">decode</span></tt>
that takes a single encoded string as an argument and returns the original message.
</p>
<pre>
<span class="prompt">>>></span> decode(<span class="string">'lTretsxty qocfz aeunrcoomdliknegv zfzuwnfcrtzixotn')</span>
<span class="result"></span> 'Test of encoding function'
</pre>
<p>
This can also be done using string slicing in just one line!
</p>
<h2>Week 11 (Recursion): Alphabetic Words</h2>
<i>Comment: This task was originally going to be a warm-up towards the
file-traversal one, but the task statement is a little too complicated.</i>
<p>
This task is to determine how two words should compare in an alphabetic
ordering, without distinguishing between lowercase and uppercase. Specifically,
write a function <tt>compare(a, b)</tt> which takes two strings, and returns
<tt>-1</tt> if <tt>a</tt> occurs before <tt>b</tt>
in alphabetic order, <tt>1</tt> if <tt>b</tt> occurs before <tt>a</tt>, and
<tt>0</tt> if they are the same word (up to capitalisation). The alphabetic
ordering of two words is defined as follows:
</p>
<ul>
<li>If both strings are empty, then they are the same.</li>
<li>If just one of the strings is empty, then it occurs before the other.</li>
<li>If the first letter of each word is different, then the ordering of those
letters determines the ordering of the words.</li>
<li>If the first letter of each word is the same, then compare the remaining
words after removing the first letter from each.</li>
</ul>
<p>
For example:
</p>
<pre>
<span class="prompt">>>></span> compare(<span class="string">'coconut'</span>, <span class="string">'Cocoon'</span>)
-1
<span class="prompt">>>></span> compare(<span class="string">'swordfish'</span>, <span class="string">'sword'</span>)
1
<span class="prompt">>>></span> compare(<span class="string">'AppLE'</span>, <span class="string">'aPple'</span>)
0
</pre>
<p>
It is safe to assume that both inputs contain only letters.
</p>
<h2>Recursion: List Sorting</h2>
<i>A bit too hard for a warm-up task.</i>
<p>
Sorting a list of data is a common task in many applications of computing.
There are many different methods (or <i>algorithms</i>) for sorting data, one
such method, called <i>insertion sort</i> is as follows: first find the
smallest element, 'remove' it from the list, then sort the remaining elements,
and insert the smallest element back in front of the list.
</p>
<p>
Write a recursive function <tt>sort</tt> which takes a list, and returns a
sorted version of the list using this method.
</p>
<div class="important">
<b>Hint:</b>
<p>
It may help to use the <tt><span class="builtin">min</span></tt> function and
<tt>list.index</tt> method, as well as list slicing.
</p>
<pre>
<span class="prompt">>>></span> nums = [5, 2, 4, 1, 3]
<span class="prompt">>>></span> <span class="builtin">min</span>(nums)
<span class="result">1</span>
<span class="prompt">>>></span> nums.index(1)
<span class="result">3</span>
<span class="prompt">>>></span> nums[3] == 1
<span class="result">True</span>
<span class="prompt">>>></span> nums[:3] + nums[4:]
<span class="result">[5, 2, 4, 3]</span>
</pre>
</div>