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
最赞回答 / Awful_Leo
这是你的函数:def average(*args): sum=0.0 if len(args)==0: print 0.0 else : for x in args: sum=sum+x return sum/len(args)print average() #0.0 Noneprint average(1, 2) #1.5print average(1, 2, 2, 3, 4) #2.4在你的函数中,在不传入参数时,先打印0...
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