import math
def quadratic_equation(a, b, c):
m = b * b - 4 * a * c
if m > 0:
x = (-b + math.sqrt(m))/(2 * a)
y = (-b - math.sqrt(m))/(2 * a)
return x, y
elif m == 0:
x = -b/(2 * a)
return x
else:
return
def quadratic_equation(a, b, c):
m = b * b - 4 * a * c
if m > 0:
x = (-b + math.sqrt(m))/(2 * a)
y = (-b - math.sqrt(m))/(2 * a)
return x, y
elif m == 0:
x = -b/(2 * a)
return x
else:
return
2016-02-23
def square_of_sum(L):
sum = 0
x = 0
while x < len(L):
sum = sum + L[x]*L[x]
x = x + 1
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
x = 0
while x < len(L):
sum = sum + L[x]*L[x]
x = x + 1
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-02-23
L = ['Adam', 'Lisa', 'Bart']
L[0] = 'Bart'
L[-1] = 'Adam'
print L
L[0] = 'Bart'
L[-1] = 'Adam'
print L
2016-02-23
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 y>x:
print x*10+y
(0是多余的)
for y in [1,2,3,4,5,6,7,8,9,]:
if y>x:
print x*10+y
(0是多余的)
2016-02-23
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
L.pop(3)
L.pop(2)
print L
2016-02-23
L = ['Adam', 'Lisa', 'Bart']
L.insert(2,'Paul')
print L
L.insert(2,'Paul')
print L
2016-02-23
sum = 0
x = 1
while x / 2 && x <= 100:
sum += x
print sum
x = 1
while x / 2 && x <= 100:
sum += x
print sum
2016-02-23
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[-1]
print L[0]
print L[1]
print L[2]
print L[-1]
2016-02-23
L = ['Adam',95.5,'Lisa',85,'Bart',59]
print L
print L
2016-02-23