额,为什么感觉自己编的和大家有点不同。。。。。(别喷我,我以前学C#的)
做了个简单测试,虽然防不住某些变态输入(比如None啊,非数字值啊,各种各样的东西往参数里放)但是能用
注:这算是连着的吧,太长了一次发不出
def quadratic_equation(a, b, c):
if a == 0:
return ( None )
做了个简单测试,虽然防不住某些变态输入(比如None啊,非数字值啊,各种各样的东西往参数里放)但是能用
注:这算是连着的吧,太长了一次发不出
def quadratic_equation(a, b, c):
if a == 0:
return ( None )
2015-08-08
else:
temp = math.pow(b, 2) - 4 * a * c
if temp < 0:
return ( None )
elif temp == 0:
return ( (0 - b)/(2 * a) )
else:
temp2 = math.sqrt(temp)
return ( ((0 - b) + temp2)/(2 * a), ((0 - b) - temp2)/(2 * a) )
temp = math.pow(b, 2) - 4 * a * c
if temp < 0:
return ( None )
elif temp == 0:
return ( (0 - b)/(2 * a) )
else:
temp2 = math.sqrt(temp)
return ( ((0 - b) + temp2)/(2 * a), ((0 - b) - temp2)/(2 * a) )
2015-08-08
def average(*args):
if len(args)==0:
return 0.0
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-08-07
L=[]
for x in range(1,10):
for y in range(1,10):
for z in range(1,10):
if x==z:
L.append(x*100+y*10+z)
print L
我写的代码好难看.......
for x in range(1,10):
for y in range(1,10):
for z in range(1,10):
if x==z:
L.append(x*100+y*10+z)
print L
我写的代码好难看.......
2015-08-07
raw字符串,Unicode字符串,短路运算,list,append()方法,insert()方法,pop()方法,tuple,tuple单元素,dict{},len(),get()方法,set([]),in操作符,add()方法,remove()方法,abs()绝对值,cmp()比较,math包sqrt()函数,定义可变参数*,切片[::],range()函数,字符串upper()方法,索引迭代enumerate(),zip()函数,values()方法,items()方法,列表生成式,字符串join()方法,条件过滤,isinstance(x,str)函数,多层表达式\\~~//
2015-08-07
这样可以过
L = [95.5, 85, 59,1]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
L = [95.5, 85, 59,1]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
2015-08-07
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
2015-08-06
t = ('a', 'b', 'A', 'B')
print t
这样改为什么不行???
print t
这样改为什么不行???
2015-08-06
sum = 0
x = 1
while x<=100:
sum=sum+x
print sum
老师,这个的答案验证有问题。
x = 1
while x<=100:
sum=sum+x
print sum
老师,这个的答案验证有问题。
2015-08-06
print [ x * 100 + y * 10 + z for x in range(1,10) for y in range(0,10) for z in range(0,10) if x == z]
2015-08-06
print [a+b+a for a in '123456789' for b in '0123456789'for a in '123456789' ]
2015-08-06
L = [95.5, 85, 59]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
代码不应该就是这样么。最后一个是报错。晕。上一个为什么这么写就过不了!
print L[-1]
print L[-2]
print L[-3]
print L[-4]
代码不应该就是这样么。最后一个是报错。晕。上一个为什么这么写就过不了!
2015-08-06
采用配方法
ax^2+bx+c=0
两边同除以a得
x^2+(b/a)x+c/a=0
x^2+b/ax+(b/2a)^2=(b/2a)^2-c/a
(x+b/2a)^2=(b^2-4ac)/4a^2
当b^2-4ac<0时 无解
当b^2-4ac>=0时
x+b/2a=±(√b^2-4ac/2a)
x=(-b±√b^2-4ac)/2a
ax^2+bx+c=0
两边同除以a得
x^2+(b/a)x+c/a=0
x^2+b/ax+(b/2a)^2=(b/2a)^2-c/a
(x+b/2a)^2=(b^2-4ac)/4a^2
当b^2-4ac<0时 无解
当b^2-4ac>=0时
x+b/2a=±(√b^2-4ac/2a)
x=(-b±√b^2-4ac)/2a
2015-08-06