def double = []
for element in sequence:
result = result + [element * 2]
return result
File "/tmp/ipykernel_2706/264923829.py", line 1 def double = [] ^ SyntaxError: invalid syntax
def double(sequence):
result = []
for element in sequence
result = result + [element * 2]
return result
File "/tmp/ipykernel_2706/1845139530.py", line 3 for element in sequence ^ SyntaxError: invalid syntax
def double(sequence):
result = []
for element in sequence:
result = result + [element * 2]
return result
def double([1, 10, 5]):
result = []
for element in sequence:
result = result + [element * 2]
return result
File "/tmp/ipykernel_2706/2322150171.py", line 1 def double([1, 10, 5]): ^ SyntaxError: invalid syntax
double([1, 10, 5])
[2, 20, 10]
double([-42, 0, 42])
[-84, 0, 84]
double([1, 2, 3, 4, 5, 6, 7, 8, 9])
[2, 4, 6, 8, 10, 12, 14, 16, 18]
double([24])
[48]
double([])
[]
double([bird])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_2706/2459904396.py in <module> ----> 1 double([bird]) NameError: name 'bird' is not defined
double()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2706/2608569975.py in <module> ----> 1 double() TypeError: double() missing 1 required positional argument: 'sequence'
triple([3])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_2706/3928093067.py in <module> ----> 1 triple([3]) NameError: name 'triple' is not defined
# this is a comment using hash
this is a comment using the markdown cell type
# the function double() doubles each number inbetween the bracketts
double(x)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_2706/2622359982.py in <module> ----> 1 double(x) NameError: name 'x' is not defined
double(x)
x = 2
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_2706/4124774468.py in <module> ----> 1 double(x) 2 x = 2 NameError: name 'x' is not defined
double(x)
x = [2]
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_2706/3528263217.py in <module> ----> 1 double(x) 2 x = [2] NameError: name 'x' is not defined
x = [2]
double(x)
[4]
x = 2
double(x)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2706/1861958353.py in <module> 1 x = 2 ----> 2 double(x) /tmp/ipykernel_2706/1900838742.py in double(sequence) 1 def double(sequence): 2 result = [] ----> 3 for element in sequence: 4 result = result + [element * 2] 5 return result TypeError: 'int' object is not iterable
y = [2]
double(y)
[4]
x = [1, 2, 3]
double(x)
[2, 4, 6]
x
[1, 2, 3]
y
[2]
# the function double() doubles each element of the sequence inside the bracketts, while the original data doesn´t change
double(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2706/1555949217.py in <module> ----> 1 double(5) /tmp/ipykernel_2706/1900838742.py in double(sequence) 1 def double(sequence): 2 result = [] ----> 3 for element in sequence: 4 result = result + [element * 2] 5 return result TypeError: 'int' object is not iterable
double([1, 2], [3, 4])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2706/1017459985.py in <module> ----> 1 double([1, 2], [3, 4]) TypeError: double() takes 1 positional argument but 2 were given