def square_of_sum(L):
return sum([x*x for x in L])
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
return sum([x*x for x in L])
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-05-18
L = []
n = 1
while n<=100:
L.append(n*n)
n = n+1
print sum(L)
n = 1
while n<=100:
L.append(n*n)
n = n+1
print sum(L)
2018-05-18
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print str(x[0]), ':' ,int(x[1])
for x in s:
print str(x[0]), ':' ,int(x[1])
2018-05-18
s = set(['adam', 'Lisa', 'bart', 'Paul'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2018-05-18
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key+':'+str(d.get(key))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key+':'+str(d.get(key))
2018-05-18
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
2018-05-18
for x in [ '1','2','3','4','5','6','7','8','9']:
for y in [ '1','2','3','4','5','6','7','8','9']:
if x<y:
print x+y
for y in [ '1','2','3','4','5','6','7','8','9']:
if x<y:
print x+y
2018-05-18
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum = sum + x
print sum
2018-05-18
sum = 0
x = 1
n = 1
while True:
sum = sum + 2**(n-1)
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + 2**(n-1)
n = n + 1
if n > 20:
break
print sum
2018-05-18