tax(1500)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_9620/757572318.py in <module> ----> 1 tax(1500) NameError: name 'tax' is not defined
def tax(subtotal):
return subtotal*0.08875
tax(1500)
133.125
1500*0.08875
133.125
1500+tax(1500)
1633.125
200+1500+tax(1500)
1833.125
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
set_a()
The value of a: 10
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
l=[7,4,2,6]
print(num)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_9620/302864193.py in <module> ----> 1 print(num) NameError: name 'num' is not defined
def mean(sequence):
for element in sequence:
total=total+element
return total/len(sequence)
mean(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_9620/952054573.py in <module> ----> 1 mean(5) /tmp/ipykernel_9620/515362635.py in mean(sequence) 1 def mean(sequence): ----> 2 for element in sequence: 3 total=total+element 4 return total/len(sequence) TypeError: 'int' object is not iterable
mean(5,6,7)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_9620/45238786.py in <module> ----> 1 mean(5,6,7) TypeError: mean() takes 1 positional argument but 3 were given
def mean(sequence):
total=0
for element in sequence:
total=total+element
return total/len(sequence)
mean(5)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_9620/952054573.py in <module> ----> 1 mean(5) /tmp/ipykernel_9620/1027729532.py in mean(sequence) 1 def mean(sequence): 2 total=0 ----> 3 for element in sequence: 4 total=total+element 5 return total/len(sequence) TypeError: 'int' object is not iterable
short=[5,5,5,5]
mean(short)
5.0
x=5
type(x)
int
type(5)
int
x='hello world'
type(x)
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_9620/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_9620/2596768515.py in <module> ----> 1 2+'hello' TypeError: unsupported operand type(s) for +: 'int' and 'str'
len(str(5))
1
str(2)+'hello'
'2hello'
'2'+'hello'
'2hello'
len('5')
1
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
[4.0]
result=result+4.0
result
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_9620/3429417297.py in <module> ----> 1 result=result+4.0 2 result TypeError: can only concatenate list (not "float") to list
2+2==4
True
2+2==3
False
2+2==3+1
True
greeting='hello'
greeting=='hi'
False
greeting=='hello'
True
greeting='hi'
greeting=='hi'
True
def secret(word):
if word=='please':
return 'Yes!'
secret('hello')
secret('world')
secret('please')
'Yes!'
secret('Please')
def yesno(word):
if word=='yes':
return True
if word=='no':
return False
yesno('no')
False