s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x not in s:
s.add(x)
else:
s.remove(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x not in s:
s.add(x)
else:
s.remove(x)
print s
2018-04-29
L=[]
def square_of_sum(list):
for i in list:
L.append(i*i)
return sum(L)
print square_of_sum([1,2,3,4])
def square_of_sum(list):
for i in list:
L.append(i*i)
return sum(L)
print square_of_sum([1,2,3,4])
2018-04-28
有人说评论区一大堆超纲的。。。。。。。emmmmmmmmm..........超纲了你可以不看啊。。。。。。。别人只是提供了更多的方式,你可以去学习,去了解,在现有基础上扩展,难道不是很好么?这也怪,,,我觉得你不适合学这个。。。。。。
2018-04-28
import math
def quadratic_equation(a, b, c):
delta = math.sqrt(b*b-4*a*c)
x1 = (delta-b)/(2*a)
x2 = (delta*(-1)-b)/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
delta = math.sqrt(b*b-4*a*c)
x1 = (delta-b)/(2*a)
x2 = (delta*(-1)-b)/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-04-28
建议换些例题。这涉及高中数学,提示的时候也应该列出公式。太难会造成学员厌学的。
知道公式基本就是照抄了,有两个结果,蛋疼不。。。
搞的这么变态,学员会怀疑人生的。
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b*b-4*a*c)
x = (-b + t)/(2*a),( -b - t )/ (2 * a)
return x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
知道公式基本就是照抄了,有两个结果,蛋疼不。。。
搞的这么变态,学员会怀疑人生的。
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b*b-4*a*c)
x = (-b + t)/(2*a),( -b - t )/ (2 * a)
return x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-04-28
def square_of_sum(L):
result = 0
for i in L:
result += i*i
return result
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
result = 0
for i in L:
result += i*i
return result
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-04-28