print [100*x+10*y+z for x in range(1,10) for y in range(0,10) for z in range(0,10) if z==x ]
2019-05-01
def toUppers(L):
return [x.upper() for x in L if isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
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)
2019-05-01
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.itervalues():
sum=sum+v
print sum/len(d)
sum = 0.0
for v in d.itervalues():
sum=sum+v
print sum/len(d)
2019-05-01
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,5),L):
print index, '-', name
for index, name in zip(range(1,5),L):
print index, '-', name
最赞回答 / 该用户暂未设置昵称
你在suffer后面多写了个单引号,参考代码:print r'''"To be,or not to be":that is the question.Whether it's nobler in the mind to suffer.'''
2019-05-01
def average(*args):
sum=0.0
if len(args)==0:
return sum
for x in args:
sum=sum+x
return sum/len(args)
sum=0.0
if len(args)==0:
return sum
for x in args:
sum=sum+x
return sum/len(args)
2019-05-01
L = []
x=1
while True:
L.append(x*x)
x+=1
if x>100:
break
print sum(L)
x=1
while True:
L.append(x*x)
x+=1
if x>100:
break
print sum(L)
2019-05-01
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]
2019-05-01