没用过len():
def average(*args):
n = 0
s = 0.0
for x in args:
n += 1
s +=x
if n > 0:
return s/n
else:
return s
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
def average(*args):
n = 0
s = 0.0
for x in args:
n += 1
s +=x
if n > 0:
return s/n
else:
return s
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-04-04
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:'+str(d.get('Adam'))
print 'Lisa:'+str(d.get('Lisa'))
print 'Bart:'+str(d.get('Bart'))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:'+str(d.get('Adam'))
print 'Lisa:'+str(d.get('Lisa'))
print 'Bart:'+str(d.get('Bart'))
2018-04-04
months = set(['Feb','Jun'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2018-04-04
print [x*100 + y*10 + z for x in range(1, 10) for y in (range(0, 10)) for z in range(1, 10) if x == z]
2018-04-04
L = range(1,101)
print L
B = []
for x in L:
y =x * x
B.append(y)
print B
print sum(B)
print L
B = []
for x in L:
y =x * x
B.append(y)
print B
print sum(B)
2018-04-04
sum = 0
x = 1
n = 1
while True:
sum=x*(pow(2,n)-1)
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum=x*(pow(2,n)-1)
n=n+1
if n>20:
break
print sum
2018-04-04
L = []
x = 1
while True:
if x > 100:
break
L.append(x*x)
x = x + 1
print sum(L)
x = 1
while True:
if x > 100:
break
L.append(x*x)
x = x + 1
print sum(L)
2018-04-04
def average(*args):
if len(args) == 0:
return 0.0
else:
return sum(args)/float(len(args))
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
#########
这样,在调用的时候,可以这样写:
>>> average()
0
......
#############
判别接口 index.py 设置的逻辑和题目例子不一致,误导人
if len(args) == 0:
return 0.0
else:
return sum(args)/float(len(args))
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
#########
这样,在调用的时候,可以这样写:
>>> average()
0
......
#############
判别接口 index.py 设置的逻辑和题目例子不一致,误导人
2018-04-04
sum = 0
x = 1
while x <= 100:
sum += x
x +=2
print sum
x = 1
while x <= 100:
sum += x
x +=2
print sum
2018-04-04
score = 85
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
2018-04-04
瞎敲的居然通过了
L = ['Adam', 'Lisa', 'Bart']
L.reverse()
print L
L = ['Adam', 'Lisa', 'Bart']
L.reverse()
print L
2018-04-04