def average(*args):
sum = 0.0
for i in args:
sum += i
if len(args) == 0:
return 0.0
else:
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
for i in args:
sum += i
if len(args) == 0:
return 0.0
else:
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2017-02-11
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = 2**n
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = 2**n
n = n + 1
if n > 20:
break
print sum
2017-02-11
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k, ':', v
print 'average', ':', sum / len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k, ':', v
print 'average', ':', sum / len(d)
2017-02-10
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for score in d.itervalues():
sum = sum + score
print sum / 4
sum = 0.0
for score in d.itervalues():
sum = sum + score
print sum / 4
2017-02-10
print '''\"To be, or not to be\": that is the question.
Whether it\'s nobler in the mind to suffer.'''
print r'''"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 r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
2017-02-10
print r'''"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.'''
2017-02-10
a='python was started in 1989 by \'guido\'\npython is free and easy to learn'
print a
print a
2017-02-10
for x in [0,1,2,3,4,5,6,7,8,9]:
for y in [ 0,1,2,3,4,5,6,7,8,9]:
if x<y:
print str(x)+str(y)
简单粗暴,但是还有其他好方法
for y in [ 0,1,2,3,4,5,6,7,8,9]:
if x<y:
print str(x)+str(y)
简单粗暴,但是还有其他好方法
2017-02-10