sum = 0
x = 1
n = 1
while True:
sum+=x
n+=1
x*=2
if n>20:
break
print sum
x = 1
n = 1
while True:
sum+=x
n+=1
x*=2
if n>20:
break
print sum
2016-08-03
d.items(): 是获取到字典中所有的item 即 (key ,value)
d.itervalues / d.values 是获取到d中的所有value
enumerate(L):是获取到list中所有的(index,name)
d.itervalues / d.values 是获取到d中的所有value
enumerate(L):是获取到list中所有的(index,name)
2016-08-03
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum+=score
print sum / 4
sum = 0.0
for score in L:
sum+=score
print sum / 4
2016-08-03
其实 index, name 本质是一个tuple 在python中是可以省去()的 于是当我们for (index, name) in enumerate(L):
print index + 1, '-', name写也是可以的
print index + 1, '-', name写也是可以的
#tuple就不可变了
t = ('a', 'b', ('A', 'B'))
print t
t = ('a', 'b', ('A', 'B'))
print t
2016-08-03
x1 = 1
d = 3
n = 100
x100 = x1 + (n-1)*d
s = n * x1 + ( ( n * ( n - 1 ) ) / 2 ) * d
print s
d = 3
n = 100
x100 = x1 + (n-1)*d
s = n * x1 + ( ( n * ( n - 1 ) ) / 2 ) * d
print s
2016-08-03
L = ['Adam',95.5,'Lisa',85,'Bart',59]
print L
print L
2016-08-03
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2016-08-03
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2016-08-03