sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum = sum + x
print sum
2015-04-26
age = 20
if age < 6:
print 'kid'
elif age < 18:
print 'teenager'
else:
print 'adult'
if age < 6:
print 'kid'
elif age < 18:
print 'teenager'
else:
print 'adult'
2015-04-25
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]
2015-04-25
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L
过了,第四个就是让我们认识到错误
print L[0]
print L[1]
print L[2]
print L
过了,第四个就是让我们认识到错误
2015-04-25
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[2]
print L[0]
print L[1]
print L[2]
print L[2]
2015-04-25
def average(*args):
sum = 0
t = float(len(args))
if t == 0 :
return 0.0
else:
for x in args:
sum += x
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0
t = float(len(args))
if t == 0 :
return 0.0
else:
for x in args:
sum += x
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-24
def square_of_sum(L):
sum = 0
for x in L:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in L:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-04-24