4 + 4.5 + 0.375
8.875
4 + 4.5 + .375
8.875
1500 * 0.08875
133.125
995.50 * 0.08875
88.350625
def tax(subtotal):
return subtotal * 0.08875
def return(subtotal):
return subtotal * 0.08875
File "/tmp/ipykernel_3313/1135345869.py", line 1 def return(subtotal): ^ SyntaxError: invalid syntax
return ([])
File "/tmp/ipykernel_3313/2375654493.py", line 1 return ([]) ^ SyntaxError: 'return' outside function
tax(1500)
133.125
tax(9)
0.79875
9 * 0.08875
0.79875
1500 + tax(1500)
1633.125
200 + 1500 + tax(1500)
1833.125
200 + 1500 + tax(200)
1717.75
* 0.08875
File "/tmp/ipykernel_3313/2543705064.py", line 4 SyntaxError: can't use starred expression here
sum = 1500
sum = sum + sum * 0.08875 # Add the tax amount
sum
1633.125
sum + sum
3266.25
def set_a():
a = 10
print('The value of a:',a)
set_a()
The value of a: 10
a = 20
print('Initially, the value of a:',a)
set_a()
print('Finally, the value of a:',a)
Initially, the value of a: 20 The value of a: 10 Finally, the value of a: 20
def scoped(first, second):
third = second + second - first
return third
first = 10
second = 11
third = 12
scoped(2, 4)
6
first
10
second
11
third
12
def scoped(la, lala):
lalala = lala + lala - la
return lalala
first = 10
second = 11
third = 12
scoped(2, 4)
6
l = [7, 4, 2, 6]
for num in l:
print(num)
7 4 2 6
for num in l:
print(num * 2)
14 8 4 12
def mean(sequence):
for element in sequence:
total = total + element
return total / len(sequence)
temperature - 80
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/3334237015.py in <module> ----> 1 temperature - 80 NameError: name 'temperature' is not defined
def mean(sequence):
total = 0
for element in sequence:
total = total + element
return total / len(sequence)
short = [5, 5, 5, 5]
mean(short)
5.0
short = [-5, 0, 5]
mean(short)
0.0
l = [7, 4, 2, 6]
mean(l)
4.75
x = 5
type(x)
int
type(5)
int
x = 'hello world'
type(x)
str
'hello world'
'hello world'
type('hello world')
str
type([1, 2, 3])
list
'hello'+'world'
'helloworld'
'knock' + 'knock'
'knockknock'
a = 'hello'
b = 'world'
a + b
'helloworld'
len('hello world')
11
len([1, 2, 3])
3
len(['hello', 'world'])
2
len(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/4108502181.py in <module> ----> 1 len(5) TypeError: object of type 'int' has no len()
2 + 'hello'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/2556979404.py in <module> ----> 1 2 + 'hello' TypeError: unsupported operand type(s) for +: 'int' and 'str'
'hello' - 'lo'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/1096853183.py in <module> ----> 1 'hello' - 'lo' TypeError: unsupported operand type(s) for -: 'str' and 'str'
len(str(5))
1
str(2) + 'hello'
'2hello'
'eindhoven' + 'housing' + str(4) + 'eva'
'eindhovenhousing4eva'
volume = [4.0, 2.0, 3.0, 5.5]
result = []
for element in volume:
result = result + [element * 2]
result
[8.0, 4.0, 6.0, 11.0]
result = []
result
[]
result = result + [4.0]
result
[2.0, 4.0]
result = result + [2.0]
result
[2.0, 4.0, 2.0]
result = result + [3.0]
result
[2.0, 4.0, 2.0, 3.0]
result = result + [5.5]
result
[2.0, 4.0, 2.0, 3.0, 5.5]
result = []
result = result + 4.0
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/2651487680.py in <module> 1 result = [] 2 ----> 3 result = result + 4.0 TypeError: can only concatenate list (not "float") to list
words = ['hello', 'world']
double(words)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/2412218211.py in <module> ----> 1 double(words) NameError: name 'double' is not defined
def double(sequence):
result = [ ]
for element in sequence:
result = result + [element * 2]
return result
words = ['hello', 'world']
double(words)
['hellohello', 'worldworld']
countdown = [3, 2, 1, 'contact']
double(countdown)
[6, 4, 2, 'contactcontact']
double('abstraction')
['aa', 'bb', 'ss', 'tt', 'rr', 'aa', 'cc', 'tt', 'ii', 'oo', 'nn']
2 + 2 == 4
True
2 + 2 == 3
False
x = 2 - 1
2 + x == 3
True
str(2) == 1
False
2 + 2 == 3 + 1
True
2 + 2 == 2 + 1
False
greeting = 'hello'
greeting == 'hello'
True
greeting == 'hi'
False
instrument = 'trumpet', 'piano', 'violin'
instrument == 'trumpet', 'piano', 'violin'
(False, 'piano', 'violin')
instrument = (['trumpet', 'piano', 'violin'])
instrument == ['trumpet']
False
instrument == 'trumpet'
False
belly = 'button'
belly == 'button'
True
6 + 5 == 11
True
x = 2.1
x / x
1.0
1.0 == x / x
True
instrument = ['trumpet', 'piano', 'violin']
instrument == 'trumpet'
False
instrument == 'trumpet', 'piano' , 'violin'
(False, 'piano', 'violin')
instrument == ['trumpet', 'piano', 'violin']
True
double(str(1))
['11']
double(str(1)) == 11
False
double(str(1)) == '11'
False
double(str(1)) == ['11']
True
1001 * 3
3003
3003 == 1001
False
1001 / 3
333.6666666666667
1001 / 3 == 333.6666666666667
True
a = b
a + a
'worldworld'
c = 'd'
c + c
'dd'
def secret(word):
if word == 'please':
return 'Yes!'
secret('hello')
secret('world')
secret('please')
'Yes!'
def secret(word):
if not word == 'please':
return 'Hell no!'
secret('hi')
'Hell no!'
secret(' please')
'Hell no!'
def yesno(word):
if word == 'yes':
return True
if word == 'no':
return False
yesno('haha')
yesno('no')
False
yesno('yes')
True
yesno('Yes')
yesno('oui')
def secret(word):
if word == 'please':
return 'Yes!'
else:
return 'No.'
def secret(word):
if word == 'please':
return True
else:
return False
def secret(word):
return (word == 'please')
1 / 4
0.25
A / 0
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/3403241644.py in <module> ----> 1 A / 0 NameError: name 'A' is not defined
A + 0
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/1742633547.py in <module> ----> 1 A + 0 NameError: name 'A' is not defined
A = 9
B = 9
A + B
18
A - B
0
A * B
81
A / B
1.0
A / 0
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) /tmp/ipykernel_3313/3403241644.py in <module> ----> 1 A / 0 ZeroDivisionError: division by zero
0 / 0
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) /tmp/ipykernel_3313/4154377607.py in <module> ----> 1 0 / 0 ZeroDivisionError: division by zero
A + 0
9
A * 0
0
A - 0
9
'hi' * 2
'hihi'
'hihi' / 2
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/3445710781.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([8])
[4.0]
def half(sequence):
result = [ ] / 2
return result
half([19])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/1274113115.py in <module> ----> 1 half([19]) /tmp/ipykernel_3313/3570830606.py in half(sequence) 1 def half(sequence): 2 ----> 3 result = [ ] / 2 4 5 return result TypeError: unsupported operand type(s) for /: 'list' and 'int'
def half(sequence):
result = [ ]
for element in sequence:
result = result /2
return result
half([19])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/1274113115.py in <module> ----> 1 half([19]) /tmp/ipykernel_3313/3959974502.py in half(sequence) 5 for element in sequence: 6 ----> 7 result = result /2 8 9 return result TypeError: unsupported operand type(s) for /: 'list' and 'int'
def exclaim(sequence):
result = [ ]
for element in sequence:
result = result + [element + '!']
return result
exclaim(['watch out'])
['watch out!']
exclaim([str(2)])
['2!']
def has_no_elements(word):
if word == ' ' :
return True
else:
return False
has_no_elements('but')
False
has_no_elements(' ')
True
def sum_three(word):
result = [ ]
for element in word:
result = result + [word * 2]
if word == result:
return True
else:
return False
return result
sum_three([8])
False
sum_three(['hi'])
False
def sum_three(one, two):
three = two + two - one
return three
one = 10
two = 11
three = 12
sum_three(1, 2)
3
pshh - bam
2
def ten_times_each(sequence):
result = [ ]
for element in sequence:
result = result + [element * 10]
return result
ten_times_each([6, 9 ,12])
[60, 90, 120]
def positive(word):
result = [ ]
for element in sequence:
result = result + [element * 10]
if word == 'word':
return True
if word == '-word'
return False
return result
File "/tmp/ipykernel_3313/1057655284.py", line 13 if word == '-word' ^ SyntaxError: invalid syntax
def positive(sequence):
result = [ ]
for element in sequence:
result = result + [element * 1]
return result
positive([6, 9, 10])
[6, 9, 10]
6 > 9
False
9 < 6
False
9 > 6
True
def positive(word):
if word > 0:
return True
if word < 0:
return False
positive(5)
True
positive(-5)
False
def positive(word):
result = [ ]
for element in word:
result = result + [element * 1]
if (word) > 0:
return True
if (word) < 0:
return False
return result
positive([56])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/1961515407.py in <module> ----> 1 positive([56]) /tmp/ipykernel_3313/3125771473.py in positive(word) 7 result = result + [element * 1] 8 ----> 9 if (word) > 0: 10 11 return True TypeError: '>' not supported between instances of 'list' and 'int'
positive(56)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/20773976.py in <module> ----> 1 positive(56) /tmp/ipykernel_3313/2308868059.py in positive(word) 3 result = [ ] 4 ----> 5 for element in word: 6 7 result = result + [element * 1] TypeError: 'int' object is not iterable
positive([5])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/943697643.py in <module> ----> 1 positive([5]) /tmp/ipykernel_3313/2308868059.py in positive(word) 7 result = result + [element * 1] 8 ----> 9 if word > 0: 10 11 return True TypeError: '>' not supported between instances of 'list' and 'int'
def double(sequence):
result = [ ]
for element in sequence:
result = result + [element * 2]
return result
double([str(2), str(3), str(15)])
['22', '33', '1515']
def double(sequence):
result = [ ]
for element in sequence:
result = result + [element * 2]
return result
double(['sunshine'])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/4097762804.py in <module> ----> 1 double(['sunshine']) /tmp/ipykernel_3313/3820237830.py in double(sequence) 5 for element in sequence: 6 ----> 7 result = str(anti) + result + [element * 2] 8 9 return result NameError: name 'anti' is not defined
def double(four, eight) :
four = 'about'
eight = 'me'
four + eight + four = 12
return 12
for element in sequence:
result = result + [element * 2]
return result
def double(4, 8) :
4 = 'about'
8 = 'me'
4 + 8 + 4 = 12
return 12
for element in sequence:
result = result + [element * 2]
return result
double([8,9])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_3313/688836684.py in <module> ----> 1 double([8,9]) /tmp/ipykernel_3313/3820237830.py in double(sequence) 5 for element in sequence: 6 ----> 7 result = str(anti) + result + [element * 2] 8 9 return result NameError: name 'anti' is not defined
def pluses(thing):
result = [ ]
if thing < 0:
return ' '
return result
pluses([5])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_3313/743941960.py in <module> ----> 1 pluses([5]) /tmp/ipykernel_3313/3898044744.py in pluses(thing) 3 result = [ ] 4 ----> 5 if thing < 0: 6 7 return ' ' TypeError: '<' not supported between instances of 'list' and 'int'