d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.values():
sum = sum+i
print sum/len(d)
sum = 0.0
for i in d.values():
sum = sum+i
print sum/len(d)
2018-07-28
啊受不了了,你倒是说清楚游戏规则啊,硬是没说“一次只能移动一个盘子”这个规则,这就让我纠结半天,你这题目的意思让不明白规则的人以为可以把A上 除了底盘以外的所有盘 可以一次性移动到B盘,我就陷在这个思维里想半天“明明可以几步走完的可答案偏偏走了十几步”。说明白规则不好吗~~~~
2018-07-27
def average(*args):
sum = 0.0
n = 0
arg = 0.0
for x in args:
sum += x
n+=1
if n==0:
arg = 0.0
else:
arg=sum/n
return arg
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
n = 0
arg = 0.0
for x in args:
sum += x
n+=1
if n==0:
arg = 0.0
else:
arg=sum/n
return arg
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-07-27
def square_of_sum(L):
y = 0
for x in L:
y += x * x
return y
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
y = 0
for x in L:
y += x * x
return y
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-07-27
L = []
n = 0
while True:
n = n + 1
if n > 100:
break
else:
L.append(n*n)
print sum(L)
n = 0
while True:
n = n + 1
if n > 100:
break
else:
L.append(n*n)
print sum(L)
2018-07-27
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2018-07-27
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0],":",x[1]
for x in s:
print x[0],":",x[1]
2018-07-27
def firstCharUpper(s):
return s[0].upper() +s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper() +s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2018-07-26