sum = 0
x = 1
while x <= 100:
sum += x
x = x+1
sum = sum/2
print sum
x = 1
while x <= 100:
sum += x
x = x+1
sum = sum/2
print sum
2015-08-15
L = []
i = 1
while i <= 100:
L.append(i * i)
i += 1
print sum(L)
i = 1
while i <= 100:
L.append(i * i)
i += 1
print sum(L)
2015-08-15
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for elem in L:
if elem in s:
s.remove(elem)
else:
s.add(elem)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for elem in L:
if elem in s:
s.remove(elem)
else:
s.add(elem)
print s
2015-08-15
用用之前的方法
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,L.pop())
L.insert(1,L.pop())
print L
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,L.pop())
L.insert(1,L.pop())
print L
2015-08-15
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-08-15
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0] + ':', x[1]
for x in s:
print x[0] + ':', x[1]
2015-08-14
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name + ':',d[name]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name + ':',d[name]
2015-08-14
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')
2015-08-14
for x in [ '1','2','3','4','5','6','7','8']:
for y in [ '2','3','4','5','6','7','8','9']:
if x < y:
print x + y
for y in [ '2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2015-08-14
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
2015-08-14
sum = 0
x = 1
n = 1
while True:
sum += x
x = x * 2
if n >= 20:
break
n += 1
print sum
x = 1
n = 1
while True:
sum += x
x = x * 2
if n >= 20:
break
n += 1
print sum
2015-08-14