import math
def quadratic_equation(a, b, c):
if b**2-4*a*c>0:
x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return x1,x2
else:
return none
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if b**2-4*a*c>0:
x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return x1,x2
else:
return none
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2020-03-06
def square_of_sum(L):
s=set(L)
x=0
y=len(s)
while x+1<=y:
for a in L:
L[x]=a*a
x=x+1
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s=set(L)
x=0
y=len(s)
while x+1<=y:
for a in L:
L[x]=a*a
x=x+1
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-03-06
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
n=0
while n<4:
if L[n] in s:
s.remove(L[n])
else:
s.add(L[n])
n=n+1
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
n=0
while n<4:
if L[n] in s:
s.remove(L[n])
else:
s.add(L[n])
n=n+1
print s
2020-03-06
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2020-03-06
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.values():
sum+=v
print sum/len(d)
sum = 0.0
for v in d.values():
sum+=v
print sum/len(d)
2020-03-06
def firstCharUpper(s):
t = s.title()
return t
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
t = s.title()
return t
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-03-06
def square_of_sum(L):
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-03-05
居然用了字符串
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 x<y:
print x+y
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 x<y:
print x+y
2020-03-05