5/0
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) /tmp/ipykernel_3381/2874912419.py in <module> ----> 1 5/0 ZeroDivisionError: division by zero
'hi'*2
'hihi'
'hihi'/2
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3381/2892899560.py in <module> ----> 1 'hihi'/2 TypeError: unsupported operand type(s) for /: 'str' and 'int'
def half(sequence):
result=[]
for element in sequence:
result=result+[element/2]
return result
half([12, 16, 20])
[6.0, 8.0, 10.0]
why now it doesn't need result+???
def exclaim(sequence):
result=[]
for element in sequence:
result=result+[element+'!']
return result
exclaim(['hello','world'])
['hello!', 'world!']
exclaim(['hello', '2', 'true'])
['hello!', '2!', 'true!']
def has_no_elements(sequence):
if sequence==([]):
return True
else:
return False
has_no_elements([1])
False
has_no_elements([])
True
def sum_three(first,second,third):
result=()
result=first+second+third
return result
sum_three(1,2,3)
6
sum_three(6,45,8)
59
def ten_times_each(sequence):
result=[]
for element in sequence:
result=result+[element*10]
return result
ten_times_each([15])
[150]
def positive(sequence):
result=[]
for n in sequence:
result=result+[n==0]
return result
positive(1,4,-1)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3381/3036314541.py in <module> ----> 1 positive(1,4,-1) TypeError: positive() takes 1 positional argument but 3 were given
def one_third(sequence):
result=[]
for element in sequence:
result=result+[element/3]
return result
one_third([3])
[1.0]
one_third([15])
[5.0]
def add_half(sequence):
result=[]
for element in sequence:
result=result+[element+element/2]
return result
add_half([5])
[7.5]
add_half([46])
[69.0]