Match the words the talker speaks to the code the typist should type. Write your answers in the “Code snippet number” column
- Check if the numbers array is empty
- Return an error if n is zero, otherwise return n
- Declare an empty integer array called numbers
- Foreach loop over the numbers array
- Assert that the result is 42
- Declare a new function called foobar. It takes an integer argument called baz
- Convert n to a float
Code snippets in Python:
1
def foobar(baz):
pass
2
assert result == 42
3
for n in numbers:
pass
4
if len(numbers) == 0:
pass
5
if n == 0:
raise ValueError("n is zero")
else:
return n
6
numbers = []
7
float(n)
Code snippets in Go:
1
func foobar(baz int) {
}
2
assert.Equal(t, 42, result)
3
for n := range numbers {
}
4
if len(numbers) == 0 {
}
5
if n == 0 {
return 0, errors.New("n is zero")
}
return n, nil
6
var numbers = []int{}
7
float64(n)