L = [75, 92, 59, 68]
sum = 0.0
for aa in L:
sum += aa
print sum / len(L)
sum = 0.0
for aa in L:
sum += aa
print sum / len(L)
2018-05-28
#-*-coding:utf-8-*-#
#笨一点的办法
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
#推荐的解决方案
B = ['Adam', 'Lisa', 'Bart']
B[0]='Bart'
B[2]='Adam'
print B
#笨一点的办法
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
#推荐的解决方案
B = ['Adam', 'Lisa', 'Bart']
B[0]='Bart'
B[2]='Adam'
print B
2018-05-28
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
B = ['Adam', 'Lisa', 'Bart']
B[0]='Bart'
B[2]='Adam'
print B
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
B = ['Adam', 'Lisa', 'Bart']
B[0]='Bart'
B[2]='Adam'
print B
2018-05-28
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
L.insert(0,'Bart')
L.append('Adam')
L.pop(1)
L.pop(2)
print L
2018-05-28
import math
def quadratic_equation(a, b, c):
flag = b**2 -4*a*c
if flag > 0:
x1 = (-b+flag**0.5)/(2*a)
x2 = (-b-flag**0.5)/(2*a)
return x1,x2
elif flag == 0:
x = -b/2*a
return x
else:
print('此方程无解')
def quadratic_equation(a, b, c):
flag = b**2 -4*a*c
if flag > 0:
x1 = (-b+flag**0.5)/(2*a)
x2 = (-b-flag**0.5)/(2*a)
return x1,x2
elif flag == 0:
x = -b/2*a
return x
else:
print('此方程无解')
2018-05-28
x1 = 1
d = 3
n = 100
x100= x1 + (n-1)*d
s = x1*100+((x1+n-1)*49+50)*d
print s
d = 3
n = 100
x100= x1 + (n-1)*d
s = x1*100+((x1+n-1)*49+50)*d
print s
2018-05-27
L = []
n = 0
while n < 100:
L.insert(n,(n+1)*(n+1))
n = n + 1
print sum(L)
n = 0
while n < 100:
L.insert(n,(n+1)*(n+1))
n = n + 1
print sum(L)
2018-05-27
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
s.add('Bart')
s.remove('Adam')
s.remove('Lisa')
s.remove('Paul')
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
s.add('Bart')
s.remove('Adam')
s.remove('Lisa')
s.remove('Paul')
print s
2018-05-27
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0]+":"+str(x[1])
for x in s:
print x[0]+":"+str(x[1])
2018-05-27
s = set(['adam','bart'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2018-05-27
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k in d :
print k + ":" + str(d.get(k))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k in d :
print k + ":" + str(d.get(k))
2018-05-27
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72]='Paul'
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72]='Paul'
2018-05-27
python 3.6.5 版本 print输出需要加() 否则无法正常输出
例1:
print('你好')
例2:
s=123
print (s)
例1:
print('你好')
例2:
s=123
print (s)
2018-05-27