Skip to content

Commit 32d473d

Browse files
committed
up
1 parent 154d74a commit 32d473d

1 file changed

Lines changed: 79 additions & 3 deletions

File tree

docs/labs/lab-04.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,45 @@ title : Lab 4 - Selection in Flowgorithm
55

66
# Lab 04 : Selection in Flowgorithm
77

8+
## Before You Begin
9+
10+
Same as every lab, before you start, make sure your workspace and login are **yours**:
11+
12+
1. Open **your own** cloned folder in **VS Code** (`File``Open Folder...`). Many students share the same PC, so confirm the folder belongs to you.
13+
2. In the terminal, log out of any account with `gh auth logout`, then log back in as yourself with `gh auth login`.
14+
15+
Full steps are in [Lab 02 - Before You Begin](./lab-02.md#before-you-begin) if you need a reminder.
16+
17+
## Pull and Update in VS Code
18+
19+
This lab builds on [Lab 03](./lab-03.md). There you learned the **process** structure: adding the `Assign` shape to calculate values, running your flowchart, and exporting it to **Python**. Here you will add the missing piece, **selection**, so your flowchart can make decisions and take different paths depending on the input.
20+
21+
Before starting any lab, you need to make sure that the repo in your **GitHub** is the latest one. [Sync the repo](./lab-01.md#syncing-fork) if the `upstream` repo have been updated.
22+
23+
Once the online repo is in-sync, bring those changes down to your PC by clicking `Source Control` and then `...` beside `Changes` and click [`Pull`](./glossary.md#pull).
24+
25+
<p align="center">
26+
<img src="/public/labs/lab-02/lab-2-1.png" alt="drawing" width="400"/>
27+
</p>
28+
29+
## Checklist Before You Proceed
30+
31+
<Checklist title="Please Check Properly">
32+
33+
1. You have logged in to your Github account in the browser.
34+
2. You have logged in to your Github account in the terminal using VS Code.
35+
3. You have sync the repo in you Github account in the browser.
36+
4. You have pull the update into you repo in VS Code.
37+
38+
</Checklist>
39+
840
## Implementing Selection
941

10-
Selection in flowchart is represented by the diamond shape. In **Flowgorithm**, it is the same. Before we start using the diamond shapes, lets use one example from [Tutorial 3](../tutorials/chapter-3-tutorial-3.md) for us to implement in **Flowgorithm**
42+
Selection in flowchart is represented by the diamond shape. In **Flowgorithm**, it is the same. Before we start using the diamond shapes, lets use one example from [Tutorial 4](../tutorials/chapter-3-tutorial-4.md) for us to implement in **Flowgorithm**
1143

1244
> MyHealth magazine is sold at RM5.00 each if at least 5 units of the magazine are purchased, and it is sold at the price of RM7.00 each otherwise. Calculate the price a customer has to pay after they enter the quantity of the magazines that they purchased.
1345
14-
Lets skip the `Input` shape and `Declare` shape for the questions, if you forgot how to do that, you can refer back [here](./lab-03.md#creating-input-and-output).
46+
Lets skip the `Input` shape and `Declare` shape for the questions, if you forgot how to do that, you can refer back [here](./lab-03.md#recap-building-the-sequence).
1547

1648
After declaring input and accepting input from the user, you will got this
1749

@@ -99,7 +131,9 @@ At the top bar, click **Tools > Export to an Image file**.
99131

100132
After you click it, a popup window will appear, no need to change anything and just click **Create** atthe bottom right of the window.
101133

102-
Then it will prompt you the location that you want the image saved and the name of the image. Rename the image to `lab-4-1`.
134+
Then it will prompt you the location that you want the image saved and the name of the image. Rename the image to `lab-4-0` and save it in `/labs/lab04/example/`. Also export this walkthrough to **Python** and save it as `lab-4-0.py` in the same folder.
135+
136+
For every question in this lab you submit two files: the flowchart exported as a **PNG image** (`.png`), and the flowchart exported as a **Python file** (`.py`). To create the Python file, export the flowchart the same way you learned in [Lab 03 - Exporting Flowgorithm to Python](./lab-03.md#exporting-flowgorithm-to-python). Save both into that question's folder, using the names given in the question.
103137

104138
## Selection Questions
105139

@@ -108,6 +142,16 @@ A utility company charges RM0.30 per kWh for the first 100 kWh, RM0.50 per kWh f
108142

109143
Calculate the total bill when the customer enters their total kWh consumed.
110144

145+
Inputs (in order):
146+
147+
- `kwh` – total kWh consumed
148+
149+
Outputs (in order):
150+
151+
- `totalBill` – the total electricity bill
152+
153+
Save the PNG image as `lab-4-1.png` and the Python file as `lab-4-1.py`, both in `/labs/lab04/exercise1/`.
154+
111155
### Scenario 2 - Income Tax Slab <Badge type="warning" text="Question" />
112156
Income tax is applied as:
113157

@@ -119,6 +163,16 @@ Income tax is applied as:
119163

120164
Given an annual income, calculate total tax due.
121165

166+
Inputs (in order):
167+
168+
- `income` – annual income (RM)
169+
170+
Outputs (in order):
171+
172+
- `totalTax` – the total tax due
173+
174+
Save the PNG image as `lab-4-2.png` and the Python file as `lab-4-2.py`, both in `/labs/lab04/exercise2/`.
175+
122176
### Scenario 3 - Parking Fee <Badge type="warning" text="Question" />
123177

124178
A mall charges parking as follows:
@@ -133,6 +187,16 @@ Maximum charge per day → RM30.00
133187

134188
Given total hours parked, calculate the parking fee.
135189

190+
Inputs (in order):
191+
192+
- `hours` – total hours parked
193+
194+
Outputs (in order):
195+
196+
- `parkingFee` – the parking fee (capped at RM30.00)
197+
198+
Save the PNG image as `lab-4-3.png` and the Python file as `lab-4-3.py`, both in `/labs/lab04/exercise3/`.
199+
136200
### Scenario 4 - Baggage Allowance Logic <Badge type="warning" text="Question" />
137201

138202
A flight ticket that includes 15 kg of free baggage.Excess baggage is charged RM4.00 per kg beyond that limit.
@@ -141,4 +205,16 @@ However, if the passenger brings no baggage, they receive a RM10.00 discount on
141205

142206
Given the weight of baggage and ticket price, calculate the final price.
143207

208+
Inputs (in order):
209+
210+
- `weight` – baggage weight in kg
211+
212+
- `ticketPrice` – ticket price (RM)
213+
214+
Outputs (in order):
215+
216+
- `finalPrice` – the final price to pay
217+
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+
144220

0 commit comments

Comments
 (0)