def double(sequence):
result = [ ]
for element in sequence:
result = result + [element * 2]
return result
double([1, 10, 5])
[2, 20, 10]
double([-42, 0, 42])
[-84, 0, 84]
double ([24])
[48]
double ([])
[]
double()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2979/2608569975.py in <module> ----> 1 double() TypeError: double() missing 1 required positional argument: 'sequence'
double([34, 8*8, -9, 53, 900])
[68, 128, -18, 106, 1800]
961907 + 560166
1522073
'work' + 'shop'
'workshop'
#double() multiplies given values by 2
x = [1, 2, 3 ]
double(x)
[2, 4, 6]
x
[1, 2, 3]
x = [4, 2, 3 ]
x
[4, 2, 3]
# the double() doubles up a given sequence and rendes a new sequence with those values doubled with the original values also remaining unchanged
double(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2979/1555949217.py in <module> ----> 1 double(5) /tmp/ipykernel_2979/1416098114.py in double(sequence) 3 result = [ ] 4 ----> 5 for element in sequence: 6 7 result = result + [element * 2] TypeError: 'int' object is not iterable
double([1, 2], [3, 4])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_2979/1017459985.py in <module> ----> 1 double([1, 2], [3, 4]) TypeError: double() takes 1 positional argument but 2 were given
def triple(sequence):
result = [ ]
for element in sequence:
result = result + [element * 3]
return result
triple([9, 8, 30])
[27, 24, 90]
def tenth(sequence):
result = [ ]
for element in sequence:
result = result + [element / 10]
return result
tenth([70,45,3])
[7.0, 4.5, 0.3]
def mis(sequence):
result = [ ]
for element in sequence:
result = result + ['mis' + element]
return result
mis(['lead'])
['mislead']