d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,":",d.get(name)
Lisa : 85
Adam : 95
Bart : 59
就是得到的值排序好像很混乱
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,":",d.get(name)
Lisa : 85
Adam : 95
Bart : 59
就是得到的值排序好像很混乱
2015-06-08
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
a = 'Adam'
b = 'Lisa'
c = 'Bart'
print a,":",d.get(a)
print b,":",d.get(b)
print c,":",d.get(c)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
a = 'Adam'
b = 'Lisa'
c = 'Bart'
print a,":",d.get(a)
print b,":",d.get(b)
print c,":",d.get(c)
2015-06-08
for x in [ 1,2,3,4,5,6,7,8]:
for y in [2,3,4,5,6,7,8,9 ]:
if x<y:
print x*10+y
for y in [2,3,4,5,6,7,8,9 ]:
if x<y:
print x*10+y
2015-06-08
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-06-08
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
2015-06-08
sum = 0
x = 1
while x <= 100:
x = x + 2
sum = sum + x
print sum
x = 1
while x <= 100:
x = x + 2
sum = sum + x
print sum
2015-06-08
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum = sum + score
print sum / 4
sum = 0.0
for score in L:
sum = sum + score
print sum / 4
2015-06-08
score = 85
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2015-06-08
L = ['Adam', 'Lisa', 'Bart']
L[0] = 'Bart'
L[-1] = 'Adam'
print L
L[0] = 'Bart'
L[-1] = 'Adam'
print L
2015-06-08
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
L.pop(2)
L.pop(2)
print L
2015-06-08
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
'Paul'
L.pop(2)
'Bart'
print L
L.pop(2)
'Paul'
L.pop(2)
'Bart'
print L
2015-06-08