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
+79-3Lines changed: 79 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,45 @@ title : Lab 4 - Selection in Flowgorithm
5
5
6
6
# Lab 04 : Selection in Flowgorithm
7
7
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).
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
+
8
40
## Implementing Selection
9
41
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**
11
43
12
44
> 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.
13
45
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).
15
47
16
48
After declaring input and accepting input from the user, you will got this
17
49
@@ -99,7 +131,9 @@ At the top bar, click **Tools > Export to an Image file**.
99
131
100
132
After you click it, a popup window will appear, no need to change anything and just click **Create** atthe bottom right of the window.
101
133
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.
103
137
104
138
## Selection Questions
105
139
@@ -108,6 +142,16 @@ A utility company charges RM0.30 per kWh for the first 100 kWh, RM0.50 per kWh f
108
142
109
143
Calculate the total bill when the customer enters their total kWh consumed.
110
144
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
+
111
155
### Scenario 2 - Income Tax Slab <Badgetype="warning"text="Question" />
112
156
Income tax is applied as:
113
157
@@ -119,6 +163,16 @@ Income tax is applied as:
119
163
120
164
Given an annual income, calculate total tax due.
121
165
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/`.
0 commit comments