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
@@ -83,54 +83,55 @@ To be able to transfer the data into your `function`, you need to create a `para
83
83
84
84
** To begin lets create a function called `decode` with a single parameter called `info`**
85
85
86
-
```spy
87
-
function decode(info: string){
86
+
```python
87
+
defdecode(info):
88
88
pass
89
-
// Something will go here in step 2
90
-
}
91
89
```
92
90
93
91
## Step 2
94
92
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.
95
93
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.
97
97
98
-
```spy
99
-
function decode(info: string){
100
-
if (info === "a"){
98
+
```python
99
+
defdecode(info):
100
+
if info =="a":
101
101
return1
102
-
}
103
-
}
102
+
else:
103
+
return0
104
104
```
105
105
106
106
## Step 3
107
107
108
108
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.
109
109
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||`.
113
111
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.
120
113
114
+
| info | return |
115
+
|----------|--------|
116
+
|`a`|`1`|
117
+
|`b`|`2`|
118
+
|`c`|`3`|
119
+
|`d`|`4`|
120
+
|`other`|`0`|
121
121
122
-
```spy
123
-
function decode(info: string){
124
-
if (info === "a"){
122
+
```python
123
+
defdecode(info):
124
+
if info =="a":
125
125
return1
126
-
}else if (info === "b"){
126
+
elifinfo =="b":
127
127
return2
128
-
} // ... and so on
129
-
}
128
+
# ... and so on
129
+
else:
130
+
return0
130
131
```
131
132
132
133
## Run your code!
133
134
134
135
When you're ready, run your code and see if it works!
135
136
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