import math
def quadratic_equation(a, b, c):
x1=(-b+math.sqrt(b**2-a*c*4))/(a*2)
x2=(-b-math.sqrt(b**2-a*c*4))/(a*2)
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**2-a*c*4))/(a*2)
x2=(-b-math.sqrt(b**2-a*c*4))/(a*2)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-10-27
L = []
n=1
while True:
L.append(n*n)
n=n+1
if n>100:
break
print sum(L)
n=1
while True:
L.append(n*n)
n=n+1
if n>100:
break
print sum(L)
2019-10-27
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2019-10-27
d={'Adam':95,'Lisa':85,'Bart':59}
for dic in d:
print (dic,':',d.get(dic))
for dic in d:
print (dic,':',d.get(dic))
2019-10-27
最新回答 / 秦九州
运行到x=99时,99<100,继续x=99+1=100被continue后,也就是说这个时候因为continue,x=100不会被break而是再运行一个x=x+1,才会break,这个时候x=101,所以你会多算一个101
2019-10-26
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
name = x[0]
score = x[1]
print name ,':',score
for x in s:
name = x[0]
score = x[1]
print name ,':',score
2019-10-26
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)
2019-10-25
最新回答 / 慕的地007
def average(*args): if len(args)==0: return 0.0 return float(sum(args))/len(args) print average()print average(1, 2)print average(1, 2, 2, 3, 4)
2019-10-25
最新回答 / 慕娘0429976
import sysdef fibonacci(n): #这是一个生成器函数因为里面包含了yield指令,这个函数是用来return斐波那契里面各个项的 a, b , counter = 0, 1, 0 #分别给a, b , counter 赋值为 0, 1, 0 while True: #循环指令 if (counter > n): return #这段代码是用来关闭生成器的,因为是用return而不是yeild返回,如果再次使用next()方法会报...
2019-10-24