def square_of_sum(L):
n = 0
for k in L:
L[n] = k**2
n+=1
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
n = 0
for k in L:
L[n] = k**2
n+=1
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-04-29
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for k in L:
if k in s:
s.remove(k)
continue
s.add(k)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for k in L:
if k in s:
s.remove(k)
continue
s.add(k)
print s
2015-04-29
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for k in L:
if k in s:
s.remove(k)
else:
s.add(k)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for k in L:
if k in s:
s.remove(k)
else:
s.add(k)
print s
2015-04-29
for x in range(1,10):
for y in range(10):
if x<y:
print x*10+y
for y in range(10):
if x<y:
print x*10+y
2015-04-29
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 >0:
sum+=x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 >0:
sum+=x
print sum
2015-04-29
sum = 1
x = 1
while True:
x += 1
if x > 100:
break
if x%2 == 0:
continue
sum += x
print sum,
x = 1
while True:
x += 1
if x > 100:
break
if x%2 == 0:
continue
sum += x
print sum,
2015-04-29
sum = 0
x = 1
n = 1
while True:
if n > 20:
break
sum += x
x = x*2
n +=1
print sum
x = 1
n = 1
while True:
if n > 20:
break
sum += x
x = x*2
n +=1
print sum
2015-04-29
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':',sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':',sum/len(d)
2015-04-28
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.itervalues():
sum=sum+i
print sum/len(d)
sum = 0.0
for i in d.itervalues():
sum=sum+i
print sum/len(d)
2015-04-28