t = ('a', 'b', ('A', 'B'))
print t
print t[2]
显示:
('a', 'b', ('A', 'B'))
('A', 'B')
原来内括号里的只算一个元素。
print t
print t[2]
显示:
('a', 'b', ('A', 'B'))
('A', 'B')
原来内括号里的只算一个元素。
2015-04-29
t = ('a', 'b', 'A', 'B')
print t
print t
2015-04-29
sum = 0
x = 0
while True:
x = x + 1
if x % 2 == 0 :
continue
if x > 100:
break
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x % 2 == 0 :
continue
if x > 100:
break
sum = sum + x
print sum
2015-04-29
在move(n-1,a,c,b)的print语句上卡住了,我认为应该是print a-->b,后来突然明白函数参数的位置是a,b,c,所以a-->c其实在move(n-1,a,c,b)中就是表示print a-->b
2015-04-29
def average(*args):
n = float(len(args))
if n:
return sum(args)/n
return n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
n = float(len(args))
if n:
return sum(args)/n
return n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-29
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