def average(*args):
s = sum(args)*1.0
return 0.0 if len(args)==0 else s/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
s = sum(args)*1.0
return 0.0 if len(args)==0 else s/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-12-30
months = set([1])
x1 = 'Feb'
x2 = 'Sun'
if x1 not in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 not in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2015-12-30
# -*- coding: utf-8 -*-
d = {'Adam': 95,'Lisa': 85,'Bart': 59}
if input_score not in d.values():
print '未找到!'
else:
for name, score in d.items():
if score == input_score:
print name
d = {'Adam': 95,'Lisa': 85,'Bart': 59}
if input_score not in d.values():
print '未找到!'
else:
for name, score in d.items():
if score == input_score:
print name
2015-12-30
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for (key, value) in d.items():
print("%s: %s" % (key, value))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for (key, value) in d.items():
print("%s: %s" % (key, value))
2015-12-30
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
2015-12-30
sum = 0
x = 1
n = 1
while True:
if n <= 20:
sum += x
x *= 2
else:
break
n += 1
print sum
x = 1
n = 1
while True:
if n <= 20:
sum += x
x *= 2
else:
break
n += 1
print sum
2015-12-30
x=9
while x<100 :
x += 1
if x/10 < x%10 :
print x
else :
continue
while x<100 :
x += 1
if x/10 < x%10 :
print x
else :
continue
2015-12-30
s = set(['Adam', 'Lisa', 'Bart', 'Paul'])
temp = set()
for k in s:
l = k.lower()
temp.add(l)
for k in temp:
s.add(k)
print 'adam' in s
print 'bart' in s
temp = set()
for k in s:
l = k.lower()
temp.add(l)
for k in temp:
s.add(k)
print 'adam' in s
print 'bart' in s
2015-12-29
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2015-12-29