d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
n=len(d.items())
print (k,':',v)
print ('average', ':',sum/n )
sum = 0.0
for k, v in d.items():
sum = sum + v
n=len(d.items())
print (k,':',v)
print ('average', ':',sum/n )
2019-03-15
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum=0
for value in d.values():
sum+=value
n=len(d.values())
average=sum/n
print(sum,n,average)
sum=0
for value in d.values():
sum+=value
n=len(d.values())
average=sum/n
print(sum,n,average)
2019-03-14
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print (index+1, '-', name)
for index, name in enumerate(L):
print (index+1, '-', name)
def firstCharUpper(s):
L=s.upper()
return (L[0])
print (firstCharUpper('hello'))
print (firstCharUpper('sunday'))
print (firstCharUpper('september'))
L=s.upper()
return (L[0])
print (firstCharUpper('hello'))
print (firstCharUpper('sunday'))
print (firstCharUpper('september'))
2019-03-14
计算a or 'world'时,a='python',非空字符串,所以为True,True的话直接返回a的值,不再往后计算,而b or 'world',b='',字符串为空值,所以为False,此时计算结果取决于or 后面的值,结果为world
2019-03-14
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
print '''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
print '''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
2019-03-14
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-03-13
L = ['1','2','3','4','5','6','7','8','9']
for x in L:
for y in L:
if y > x:
print x + y
for x in L:
for y in L:
if y > x:
print x + y
2019-03-13
sum = 0
x = 1
n = 1
while True:
x = x*2
n+=1
if n==21:
sum = x - 1
break
print sum
x = 1
n = 1
while True:
x = x*2
n+=1
if n==21:
sum = x - 1
break
print sum
2019-03-13
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(-1)
L.pop(-1)
print L
L.pop(-1)
L.pop(-1)
print L
2019-03-13