import math
def quadratic_equation(a, b, c):
x1=(-b+math.sqrt(b*b-4*a*c))/(2*a)
x2=(-b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
x1=(-b+math.sqrt(b*b-4*a*c))/(2*a)
x2=(-b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-05-20
def square_of_sum(L):
L2=[]
for i in L:
L2.append(i*i)
return sum(L2)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
L2=[]
for i in L:
L2.append(i*i)
return sum(L2)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-05-20
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-05-20
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for score in d.itervalues():
sum=sum+score
print sum/len(d)
sum = 0.0
for score in d.itervalues():
sum=sum+score
print sum/len(d)
2015-05-20
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0]+':',x[1]
for x in s:
print x[0]+':',x[1]
2015-05-19
for x in [ '0','1','2','3','4','5','6','7','8','9', ]:
for y in [ '0','1','2','3','4','5','6','7','8','9' ]:
if x < y:
print x+y
额,我真是够了
for y in [ '0','1','2','3','4','5','6','7','8','9' ]:
if x < y:
print x+y
额,我真是够了
2015-05-19
def firstCharUpper(s):
for i in s[:1]:
x=i.upper()
return x+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
for i in s[:1]:
x=i.upper()
return x+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-05-19
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-05-19
L = ['Adam', 'Lisa', 'Bart']
L[0],L[-1] = L[-1],L[0]
print L
L[0],L[-1] = L[-1],L[0]
print L
2015-05-19