d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
if score >= 60:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><<td style="color:red">%s</td></tr>' % (name, score)
def generate_tr(name, score):
if score >= 60:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><<td style="color:red">%s</td></tr>' % (name, score)
2015-10-03
'''
#试试函数
def averDict(d = {}):
sum = 0
for i,v in d.iteritems():
print i,v
sum += v
print 'average', ':', float(sum)/len(d)
'''
#试试函数
def averDict(d = {}):
sum = 0
for i,v in d.iteritems():
print i,v
sum += v
print 'average', ':', float(sum)/len(d)
'''
2015-10-03
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0
for v in d.itervalues():
sum += v
print sum/(len(d))
sum = 0
for v in d.itervalues():
sum += v
print sum/(len(d))
2015-10-03
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-10-03
def greet(world = 'world'):
print 'Hello' + ' '+ world
greet()
greet('Bart')
print 'Hello' + ' '+ world
greet()
greet('Bart')
2015-10-03
def quadratic_equation(a, b, c):
temp = b**2 - 4*a*c
if temp < 0:
print '德尔塔小于零'
else:
x = (-b - math.sqrt(b**2 -4*a*c ))/(2*a)
y = (-b + math.sqrt(b**2 -4*a*c ))/(2*a)
return y,x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
temp = b**2 - 4*a*c
if temp < 0:
print '德尔塔小于零'
else:
x = (-b - math.sqrt(b**2 -4*a*c ))/(2*a)
y = (-b + math.sqrt(b**2 -4*a*c ))/(2*a)
return y,x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-10-03
def square_of_sum(L):
sum = 0
for i in L:
sum += i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for i in L:
sum += i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-10-03
L = []
for i in range(1,101):
ii = i*i
L.append(ii)
print sum(L)
for i in range(1,101):
ii = i*i
L.append(ii)
print sum(L)
2015-10-03
s = set(['Adam', 'Lisa', 'Bart', 'Paul'])
ss = set()
for i in s:
i = i.lower()
ss.add(i)
print 'adam' in ss
print 'bart' in ss
ss = set()
for i in s:
i = i.lower()
ss.add(i)
print 'adam' in ss
print 'bart' in ss
2015-10-03
for x in range(1,10):
for y in range(0,10):
if x<y:
print '%s%s'%(x,y)
for y in range(0,10):
if x<y:
print '%s%s'%(x,y)
2015-10-03
sum = 0
x = 1
while True:
x = x + 1
if x %2 == 0:
continue
else:
print x
sum += x
if x >= 99:
sum += 1
break
print sum
x = 1
while True:
x = x + 1
if x %2 == 0:
continue
else:
print x
sum += x
if x >= 99:
sum += 1
break
print sum
2015-10-03