sum = 0
x = 1
n = 1
while True:
sum += n
n *= 2
x += 1
if x > 20:
break
print sum
x = 1
n = 1
while True:
sum += n
n *= 2
x += 1
if x > 20:
break
print sum
2016-04-01
sum = 0
x = 1
while x<=100:
if x%2==1:
sum += x
print sum
x = 1
while x<=100:
if x%2==1:
sum += x
print sum
2016-04-01
L = []
x = 1
while x <= 100:
L.append(x * x)
x = x + 1
print sum(L)
x = 1
while x <= 100:
L.append(x * x)
x = x + 1
print sum(L)
2016-04-01
L = ['Adam', 'Lisa', 'Bart']
L.insert(-1,'Paul')
print L
L.insert(-1,'Paul')
print L
2016-04-01
s='Python was started in 1989 by "Guido". \n Python is free and easy to learn.'
print s
print s
2016-03-31
print 'hello, python'
print 'hello,','python'
print 'hello,','python'
2016-03-31
def greet(b='world'):
print 'hello ,' +b+'.'
greet()
greet('Bart')
print 'hello ,' +b+'.'
greet()
greet('Bart')
2016-03-31
def move(n, a, b, c):
if n==1:
print a+'-->'+c
else:
move(n-1,a,c,b)
print a+'-->'+c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
if n==1:
print a+'-->'+c
else:
move(n-1,a,c,b)
print a+'-->'+c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2016-03-31
我们在排队,队伍中有四个人, * * * * (四个人萌萌哒)
用L.pop(2)了以后, 第三个人就被无情的踢出去了队伍,就成了这样: * * *
但是排队的人,看到前面有空隙了,肯定会走上去呀. 于是就成了这样:* * *
所以如果用L.pop(3),也就是想踢掉第四个人,可是现在只有三个人了、所以L.pop(2)或者L.pop()或者L.pop(-1),都是你曾经想踢走的最后那个人。
这个往前走一步,就是所有语言中List链表的特性之一,切记。
用L.pop(2)了以后, 第三个人就被无情的踢出去了队伍,就成了这样: * * *
但是排队的人,看到前面有空隙了,肯定会走上去呀. 于是就成了这样:* * *
所以如果用L.pop(3),也就是想踢掉第四个人,可是现在只有三个人了、所以L.pop(2)或者L.pop()或者L.pop(-1),都是你曾经想踢走的最后那个人。
这个往前走一步,就是所有语言中List链表的特性之一,切记。
2016-03-31