import math
def quadratic_equation(a, b, c):
if b*b-4*a*c>0:
x1=(-b+math.sqrt(b*b-4*a*c))/2*a
x2=(-b-math.sqrt(b*b-4*a*c))/2*a
else:
print 'error'
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if b*b-4*a*c>0:
x1=(-b+math.sqrt(b*b-4*a*c))/2*a
x2=(-b-math.sqrt(b*b-4*a*c))/2*a
else:
print 'error'
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-07-20
代码仅供参考。
for x in range(1,10):
for y in range(10):
if x < y:
print x * 10 + y
for x in range(1,10):
for y in range(10):
if x < y:
print x * 10 + y
2015-07-20
def square_of_sum(L):
sum = 0
for l in L:
sum += l*l
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for l in L:
sum += l*l
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-07-20
L = []
i = 1
while(i<=100):
L.append(i*i)
i += 1
print sum(L)
i = 1
while(i<=100):
L.append(i*i)
i += 1
print sum(L)
2015-07-20
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2015-07-20
print "Python was started in 1989 by \"Guido\".\nPython is free and easy to learn."
2015-07-19
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k,v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k,v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-07-19
"两点疑虑(1)将list中的两个元素A,B改变后,其实list【0】,【1】的指针式改变的,因为先要创建两个新元素xy,在修改指针,对否?
(2)任务中题主意思显然是【】改为()但这样tuple变成内嵌tuple,而不是内嵌list,说不变有点奇异"
问题1:list中的指针确实是改变了
问题2:tuple指向一个tuple也是可以的啊
(2)任务中题主意思显然是【】改为()但这样tuple变成内嵌tuple,而不是内嵌list,说不变有点奇异"
问题1:list中的指针确实是改变了
问题2:tuple指向一个tuple也是可以的啊
2015-07-17