You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/labs/lab-04.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -217,4 +217,90 @@ Outputs (in order):
217
217
218
218
Save the PNG image as `lab-4-4.png` and the Python file as `lab-4-4.py`, both in `/labs/lab04/exercise4/`.
219
219
220
+
### Scenario 5 - Football Points <Badgetype="warning"text="Question" />
221
+
222
+
In a football league, a team earns 3 points for winning a match, 1 point for a draw, and no points for a loss. A team also collects 1 bonus point whenever the other side fails to score in that match. Given the goals each team scored, calculate the points each team takes from the match.
223
+
224
+
Inputs (in order):
225
+
226
+
-`scoreA` – goals scored by team A
227
+
228
+
-`scoreB` – goals scored by team B
229
+
230
+
Outputs (in order):
231
+
232
+
-`pointsA` – points earned by team A
233
+
234
+
-`pointsB` – points earned by team B
235
+
236
+
Save the PNG image as `lab-4-5.png` and the Python file as `lab-4-5.py`, both in `/labs/lab04/exercise5/`.
A concert ticket costs RM80. Fans who arrive more than 30 minutes before the show get RM15 off, and anyone who arrives after the show has already started is refused entry and pays nothing. Members get a further 15% off whatever they would pay. Given how many minutes before the show a fan arrives (a negative number means they arrived after it started) and whether they are a member, calculate what they pay.
241
+
242
+
Inputs (in order):
243
+
244
+
-`minutesBefore` – minutes before the show the fan arrives (negative if after it started)
245
+
246
+
-`membership` – `yes` or `no`
247
+
248
+
Outputs (in order):
249
+
250
+
-`price` – the amount the fan pays
251
+
252
+
Save the PNG image as `lab-4-6.png` and the Python file as `lab-4-6.py`, both in `/labs/lab04/exercise6/`.
A thermostat adjusts its power based on the room temperature compared to a target. When the room is colder than the target, it heats at 10 watts for every degree below. When the room is warmer, it cools at 8 watts for every degree above. When they are equal, it uses no power. The power used can never exceed 100 watts. Given the room and target temperatures, calculate the power used.
257
+
258
+
Inputs (in order):
259
+
260
+
-`tempRoom` – current room temperature
261
+
262
+
-`tempTarget` – target temperature
263
+
264
+
Outputs (in order):
265
+
266
+
-`power` – the power used in watts
267
+
268
+
Save the PNG image as `lab-4-7.png` and the Python file as `lab-4-7.py`, both in `/labs/lab04/exercise7/`.
269
+
270
+
### Scenario 8 - Taxi Fare <Badgetype="warning"text="Question" />
271
+
272
+
A taxi starts the meter at RM4, which already covers the first 2 km of the trip. Every kilometre beyond that adds RM1.20 to the fare. Rides taken after midnight have a flat RM3 surcharge added at the end. Given the trip distance and whether it is after midnight, calculate the total fare.
273
+
274
+
Inputs (in order):
275
+
276
+
-`distance` – trip distance in km
277
+
278
+
-`afterMidnight` – `yes` or `no`
279
+
280
+
Outputs (in order):
281
+
282
+
-`fare` – the total fare
283
+
284
+
Save the PNG image as `lab-4-8.png` and the Python file as `lab-4-8.py`, both in `/labs/lab04/exercise8/`.
285
+
286
+
### Scenario 9 - Cheaper Plan <Badgetype="warning"text="Question" />
287
+
288
+
A customer's monthly data can be charged in two ways, and the bill always uses whichever works out cheaper:
289
+
290
+
-**Plan A** charges RM10 as a base, plus RM1 for each GB used.
291
+
292
+
-**Plan B** charges a flat RM25 that already covers the first 20 GB. Any usage beyond 20 GB adds RM3 for each extra GB.
293
+
294
+
Given the data used, calculate the amount the customer is billed.
295
+
296
+
Inputs (in order):
297
+
298
+
-`gb` – data used in GB
299
+
300
+
Outputs (in order):
301
+
302
+
-`bill` – the amount billed
303
+
304
+
Save the PNG image as `lab-4-9.png` and the Python file as `lab-4-9.py`, both in `/labs/lab04/exercise9/`.
|**Input**| Data accepted from the user always *nouns*, never actions. **NEVER USE VERB.** <br><br>Suggested structure: <br><br> **Counter-controlled** : input_name for x times <br> **Sentinel** : input_name for x times until condition is true| enter, read, get |
14
-
|**Process**| Operations applied to the inputs arithmetic, decisions, loops. Each item should begin with a **verb**.<br><br> The suggested structure for **repetition** question is: <br><br> Counter-controlled : repeat VERB + OUTPUT + BASED ON INPUT AND CONSTANT for x times <br><br> Sentinel : repeat VERB + OUTPUT + BASED ON INPUT AND CONSTANT for x times until condition is true | calculate, compute, determine, if, while, repeat |
15
-
|**Output**| The result delivered to the user or another system again *nouns* or messages. **NEVER USE VERB.** <br><br>Suggested structure: <br><br> input_name for x times (if necessary) <br><br> or <br><br> input_name for x times until condition is true (if necessary) | display, print, show |
16
-
17
-
18
-
19
-
## Creating The Flowchart <Badgetype="warning"text="Recall" />
0 commit comments