M=b*b-4*a*c;
if a==0 and b!=0 :
return c*1.0/b;
elif a==0 and b==0 and c!=0 or M<0 :
return False;
elif M==0 :
return -b/(2*a);
else:
M=math.sqrt(M);
return (-b-M)/(2*a),(-b+M)/(2*a);
if a==0 and b!=0 :
return c*1.0/b;
elif a==0 and b==0 and c!=0 or M<0 :
return False;
elif M==0 :
return -b/(2*a);
else:
M=math.sqrt(M);
return (-b-M)/(2*a),(-b+M)/(2*a);
2016-04-02
for name in L:
if name in s:
s.remove(name);
else:
s.add(name);
if name in s:
s.remove(name);
else:
s.add(name);
2016-04-02
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in range(x+1,10):
print x*10+y
for y in range(x+1,10):
print x*10+y
2016-04-02
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2016-04-02
x1 = 1
d = 3
n = 100
x100 = (n-1)*d+x1
s = n*(x1+x100)/2
print s
d = 3
n = 100
x100 = (n-1)*d+x1
s = n*(x1+x100)/2
print s
2016-04-02
#input code
print 'hello,python'
print 'hello',',','python'
print "hello,python"
print 'hello'+','+'python'
print 'hello,python'
print 'hello',',','python'
print "hello,python"
print 'hello'+','+'python'
2016-04-02
哈哈,小白的笨办法
L = range(1, 101)
print L[:10]
print L[2::3]
print (L[4:50])[::5]
L = range(1, 101)
print L[:10]
print L[2::3]
print (L[4:50])[::5]
2016-04-02
print [i*100+j*10+k for i in range(1,10) for j in range(10) for k in range(1,10) if i*100+j*10+k==i+j*10+k*100]
2016-04-02
所有情况都当成2个盘子来处理,n个就把之前的n-1个看成一个
def move(n, a, b, c):
if n==2:
print a,'-->',b
print a,'-->',c
print b,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
def move(n, a, b, c):
if n==2:
print a,'-->',b
print a,'-->',c
print b,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2016-04-02
for x in [ 1, 2, 3, 4, 5, 6, 7, 8]:
for y in [ 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
print x * 10 + y
for y in [ 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
print x * 10 + y
2016-04-02
if else 是不是有优先级啊,不用score>=80 and score<90这种语句也可以执行。
2016-04-02