L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index + 1, '-', name
for index, name in enumerate(L):
print index + 1, '-', name
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
2015-09-25
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2015-09-25
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print list(x)[0],':',list(x)[1]
for x in s:
print list(x)[0],':',list(x)[1]
2015-09-25
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n > 20:
break
print sum
2015-09-25
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d.keys():
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d.keys():
print key,':',d[key]
2015-09-25
import math
a=1
b=2
c=1
def aquation(a,b,c):
x=b*b-4*a*c
if x<0:
return "there is on solution"
else:
x1=(-b+math.sqrt(x))/(2*a*b)
x2=(-b-math.sqrt(x))/(2*a*b)
return x1,x2
print aquation(a,b,c)
a=1
b=2
c=1
def aquation(a,b,c):
x=b*b-4*a*c
if x<0:
return "there is on solution"
else:
x1=(-b+math.sqrt(x))/(2*a*b)
x2=(-b-math.sqrt(x))/(2*a*b)
return x1,x2
print aquation(a,b,c)
2015-09-25
def firstCharUpper(s):
return s[:1].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-09-25
递归这三个步骤:
1. (n-1) a --> c
2. 1 a --> b
3. (n-1) b --> c
1. (n-1) a --> c
2. 1 a --> b
3. (n-1) b --> c
2015-09-25
def square_of_sum(L):
sum = 0
for x in L:
sum = sum + x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in L:
sum = sum + x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-09-25
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2015-09-25
记录一下,这个刚开始没有想出来。set的元素是('Adam',95),那么就可以通过下标进行访问了,学习了
2015-09-25
太好了,前面还想用list来存储一些东西进行遍历呢,现在发现了set使用起来更加方便。判断一个字符是否包含在某个集合中,就用set了
2015-09-25
s = set(['Adam','adam','bart','Bart'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2015-09-25