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
最新回答 / akira1990
不知所云,很简单的,list可以看成数组列表,而tuple则可以看成常量数组。元素相加操作要看元素的联系,同种类型可以相加,不同类型的相加会报错,需要做类型转换。字符型和整型?你确定python有字符型?python中的所有类型都是对象类型的。如果是字符串类型与整型相加,则会报错。you can try: 'test' + 32 会报错,如何处理呢?很简单,转换为字符串类型即可,'test' + str(32) 等等。
2015-05-19