s = set(['Adam','Lisa','Bart','Paul'])
b = set()
for k in s:
k = k.lower()
b.add(k)
print 'adam' in b
print 'bart' in b
b = set()
for k in s:
k = k.lower()
b.add(k)
print 'adam' in b
print 'bart' in b
2015-12-18
print 'hello,python'
print 'hello,','python'
print 'hello,','python'
2015-12-18
d = {
95:,'adam'
85:,’lisa'
45: , 'bart'
}
d[79] = 'paul'
95:,'adam'
85:,’lisa'
45: , 'bart'
}
d[79] = 'paul'
2015-12-17
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n>20:
break
print sum
2015-12-16
def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-12-16
def average(*args):
if len(args) == 0:
return 0.0
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-12-16
s = set(['Adam','Lisa','Bart','Paul'])
print s
print s
2015-12-16
def square_of_sum(L):
NL = []
for x in L:
NL.append(x**2)
return sum(NL)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
NL = []
for x in L:
NL.append(x**2)
return sum(NL)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-12-16