Skip to content

Commit 900eaf8

Browse files
Fix for incorrect block check within customts for island 5 translator 1 and requirement for a default return value from function
1 parent 90bde28 commit 900eaf8

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

tutorials/python-islands/island-5/translator/solution.py

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def decode(info):
2+
if info == "a":
3+
return 1
4+
elif info == "b":
5+
return 2
6+
elif info == "c":
7+
return 3
8+
elif info == "d":
9+
return 4
10+
else:
11+
return 0
12+
13+
# Leave this at the bottom of your code so we know to run your decode function!
14+
telescope.decode_signals()

tutorials/python-islands/island-5/translator/translator_1.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace telescope {
1818
//% block"Decode telescope bit signal"
1919
export function decode_signals(): void {
2020
// This is a bodge: makecode doesn't support Record<> for objects so `object[key]` doesn't work in the ts compiler
21-
const index_key = [WHITE_CONCRETE_POWDER, MAGENTA_CONCRETE_POWDER, LIGHT_BLUE_CONCRETE_POWDER, YELLOW_CONCRETE_POWDER]
21+
const index_key = [ORANGE_CONCRETE_POWDER, MAGENTA_CONCRETE_POWDER, LIGHT_BLUE_CONCRETE_POWDER, YELLOW_CONCRETE_POWDER]
2222
const index_value = ["a", "b", "c", "d"]
2323
// List of expected bits from user's decode() function
2424
const list_of_numbers: number[] = [1, 2, 4, 3, 2, 1]
@@ -83,54 +83,55 @@ To be able to transfer the data into your `function`, you need to create a `para
8383

8484
** To begin lets create a function called `decode` with a single parameter called `info`**
8585

86-
```spy
87-
function decode(info: string){
86+
```python
87+
def decode(info):
8888
pass
89-
// Something will go here in step 2
90-
}
9189
```
9290

9391
## Step 2
9492
Great! Now we have data being passed into the function using the `info` parameter. `info` will contain a letter, and the computer requires a matching number from that letter.
9593

96-
To start with let's return `1` when `info` is `"a"`. For this, you can use an ``||logic:if||`` statement.
94+
To start with let's return `1` when `info` is `"a"`. For this, you can use an `||logic:if||` statement.
95+
96+
After the `||logic:if||` statement, within the function, add an `||logic:else||` statement to provide a default value of `0` if the info parameter is not recognised.
9797

98-
```spy
99-
function decode(info: string){
100-
if (info === "a"){
98+
```python
99+
def decode(info):
100+
if info == "a":
101101
return 1
102-
}
103-
}
102+
else:
103+
return 0
104104
```
105105

106106
## Step 3
107107

108108
Now we have a basic `decode` function created, we need to make sure it can handle all of the inputs the computer might want us decode.
109109

110-
To do this we'll extend the ``||logic:if||`` you create with ``||logic:elif||``.
111-
112-
Use the following table create a set of ``||logic:if/else||`` statements to return the correct number.
110+
To do this we'll extend the `||logic:if||` you create with `||logic:elif||`.
113111

114-
| info | return |
115-
|--------|--------|
116-
| `a` | `1` |
117-
| `b` | `2` |
118-
| `c` | `3` |
119-
| `d` | `4` |
112+
Use the following table create a set of `||logic:if/else||` statements to return the correct number.
120113

114+
| info | return |
115+
|----------|--------|
116+
| `a` | `1` |
117+
| `b` | `2` |
118+
| `c` | `3` |
119+
| `d` | `4` |
120+
| `other` | `0` |
121121

122-
```spy
123-
function decode(info: string){
124-
if (info === "a"){
122+
```python
123+
def decode(info):
124+
if info == "a":
125125
return 1
126-
}else if (info === "b"){
126+
elif info == "b":
127127
return 2
128-
} // ... and so on
129-
}
128+
# ... and so on
129+
else:
130+
return 0
130131
```
131132

132133
## Run your code!
133134

134135
When you're ready, run your code and see if it works!
135136

136-
*Note: You will need to hit the **Reset Bit Input** button above your Agent is before you start your code!*
137+
*Note: You will need to hit the **Reset Bit Input** button above your Agent before you start your code!*

0 commit comments

Comments
 (0)