Skip to content

Commit 4ec37ca

Browse files
committed
uuu
1 parent 72b4132 commit 4ec37ca

3 files changed

Lines changed: 121 additions & 43 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default defineConfig({
4141
{ text: 'Tutorial 2', link: '/tutorials/chapter-2-tutorial-2' },
4242
{ text: 'Tutorial 3', link: '/tutorials/chapter-3-tutorial-3' },
4343
{ text: 'Tutorial 4', link: '/tutorials/chapter-3-tutorial-4' },
44-
// { text: 'Tutorial 5', link: '/tutorials/chapter-3-tutorial-5' },
44+
{ text: 'Tutorial 5', link: '/tutorials/chapter-3-tutorial-5' },
4545
// { text: 'Tutorial 6', link: '/tutorials/chapter-4-tutorial-1' },
4646
// { text: 'Tutorial 7', link: '/tutorials/chapter-4-tutorial-2' },
4747
// { text: 'Tutorial 8', link: '/tutorials/chapter-4-tutorial-3' },
@@ -165,7 +165,7 @@ export default defineConfig({
165165
{ text: 'Tutorial 2', link: '/tutorials/chapter-2-tutorial-2' },
166166
{ text: 'Tutorial 3', link: '/tutorials/chapter-3-tutorial-3' },
167167
{ text: 'Tutorial 4', link: '/tutorials/chapter-3-tutorial-4' },
168-
// { text: 'Tutorial 5', link: '/tutorials/chapter-3-tutorial-5' },
168+
{ text: 'Tutorial 5', link: '/tutorials/chapter-3-tutorial-5' },
169169
// { text: 'Tutorial 6', link: '/tutorials/chapter-4-tutorial-1' },
170170
// { text: 'Tutorial 7', link: '/tutorials/chapter-4-tutorial-2' },
171171
// { text: 'Tutorial 8', link: '/tutorials/chapter-4-tutorial-3' },

docs/labs/lab-04.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,90 @@ Outputs (in order):
217217

218218
Save the PNG image as `lab-4-4.png` and the Python file as `lab-4-4.py`, both in `/labs/lab04/exercise4/`.
219219

220+
### Scenario 5 - Football Points <Badge type="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/`.
237+
238+
### Scenario 6 - Concert Ticket <Badge type="warning" text="Question" />
239+
240+
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/`.
253+
254+
### Scenario 7 - Thermostat <Badge type="warning" text="Question" />
255+
256+
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 <Badge type="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 <Badge type="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/`.
305+
220306

docs/tutorials/chapter-3-tutorial-5.md

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,16 @@ outline: deep
66
# Chapter 3 - Tutorial 5
77

88

9-
## Creating The IPO Table <Badge type="warning" text="Recall" />
10-
11-
| Phase | Practical Meaning | Typical Keywords (in the problem text) |
12-
|------------|------------------|-----------------------------------------|
13-
| **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 <Badge type="warning" text="Recall" />
20-
21-
| Shape | Usage | Tips |
22-
|------------|----------------------|----------------------------------------------------------------------------|
23-
| Oval | Start/End | All shapes are required to be connected with arrows; be aware of the direction |
24-
| Rectangle | Process | All processes are assignment operations (=) |
25-
| Diamond | Decision/Selection | All decisions must be evaluated to `True` or `False` |
26-
| Parallelogram | Input/Output | Place Input shapes at the beginning, Output shapes at the end |
27-
28-
---
299

3010
## Pseudocode Indentation Rules <Badge type="warning" text="Recall" />
3111

3212
### IF Statement Indentation Rules
3313

3414
**Rule 1: ALL statements inside an IF block MUST be indented**
3515

16+
**CORRECT - Statements inside IF are indented:**
17+
3618
```
37-
✅ CORRECT - Statements inside IF are indented:
3819
BEGIN
3920
READ age
4021
IF age >= 18 THEN
@@ -44,8 +25,11 @@ BEGIN
4425
ENDIF
4526
PRINT "Thank you"
4627
END
28+
```
29+
30+
**WRONG - No indentation inside IF:**
4731

48-
❌ WRONG - No indentation inside IF:
32+
```
4933
BEGIN
5034
READ age
5135
IF age >= 18 THEN
@@ -59,29 +43,33 @@ END
5943

6044
**Rule 2: IF-ELSE statements require proper indentation for BOTH parts**
6145

46+
**CORRECT - Both IF and ELSE parts indented:**
47+
6248
```
63-
✅ CORRECT - Both IF and ELSE parts indented:
6449
BEGIN
6550
READ score
6651
IF score >= 80 THEN
6752
PRINT "Excellent! You passed with distinction"
68-
SET grade = "A"
53+
grade = "A"
6954
ELSE
7055
PRINT "You need to improve"
71-
SET grade = "F"
56+
grade = "F"
7257
ENDIF
7358
PRINT "Your grade is: " + grade
7459
END
60+
```
7561

76-
❌ WRONG - Inconsistent indentation:
62+
**WRONG - Inconsistent indentation:**
63+
64+
```
7765
BEGIN
7866
READ score
7967
IF score >= 80 THEN
8068
PRINT "Excellent! You passed with distinction"
81-
SET grade = "A"
69+
grade = "A"
8270
ELSE
8371
PRINT "You need to improve"
84-
SET grade = "F"
72+
grade = "F"
8573
ENDIF
8674
PRINT "Your grade is: " + grade
8775
END
@@ -91,24 +79,28 @@ END
9179

9280
**Rule 3: ALL statements inside a WHILE loop MUST be indented**
9381

82+
**CORRECT - Loop body properly indented:**
83+
9484
```
95-
✅ CORRECT - Loop body properly indented:
9685
BEGIN
97-
SET counter = 1
86+
counter = 1
9887
WHILE counter <= 5 DO
9988
PRINT "Count: " + counter
100-
SET counter = counter + 1
89+
counter = counter + 1
10190
PRINT "Next iteration coming..."
10291
ENDWHILE
10392
PRINT "Loop finished"
10493
END
94+
```
95+
96+
**WRONG - Loop body not indented:**
10597

106-
❌ WRONG - Loop body not indented:
98+
```
10799
BEGIN
108-
SET counter = 1
100+
counter = 1
109101
WHILE counter <= 5 DO
110102
PRINT "Count: " + counter
111-
SET counter = counter + 1
103+
counter = counter + 1
112104
PRINT "Next iteration coming..."
113105
ENDWHILE
114106
PRINT "Loop finished"
@@ -119,17 +111,18 @@ END
119111

120112
**Rule 4: Nested IF inside WHILE requires DOUBLE indentation**
121113

114+
**CORRECT - Nested IF properly indented:**
115+
122116
```
123-
✅ CORRECT - Nested IF properly indented:
124117
BEGIN
125-
SET num = 1
118+
num = 1
126119
WHILE num <= 10 DO
127120
IF num % 2 = 0 THEN
128121
PRINT num + " is even"
129122
ELSE
130123
PRINT num + " is odd"
131124
ENDIF
132-
SET num = num + 1
125+
num = num + 1
133126
ENDWHILE
134127
END
135128
@@ -150,7 +143,7 @@ BEGIN ← Level 0 (No indentation)
150143
ELSE ← Level 2 (Same level as IF)
151144
PRINT "Small" ← Level 3 (Inside ELSE)
152145
ENDIF ← Level 2 (Closes IF)
153-
SET value = value - 1 ← Level 2 (Inside WHILE)
146+
value = value - 1 ← Level 2 (Inside WHILE)
154147
ENDWHILE ← Level 1 (Closes WHILE)
155148
PRINT "Done" ← Level 1 (After WHILE)
156149
END ← Level 0 (Closes BEGIN)
@@ -181,8 +174,7 @@ Convert the below IPO table into a flowchart and pseudocode.
181174

182175
| **INPUT** | **PROCESS** | **OUTPUT** |
183176
|-----------|-------------|------------|
184-
| workout_minutes for 5 days | repeat determine daily_points based on workout_minutes for 5 times | total_points |
185-
| | repeat calculate total_points based on daily_points for 5 times | |
177+
| number for 5 times | repeat determine largest based on number for 5 times | largest |
186178

187179

188180
## Exercise 3 <Badge type="warning" text="Task" />
@@ -206,7 +198,7 @@ Start
206198
while temperature != -999
207199
if temperature > 30
208200
print "Hot day"
209-
set count = count + 1
201+
count = count + 1
210202
else
211203
if temperature < 10
212204
print "Cold day"

0 commit comments

Comments
 (0)