d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
2018-07-09
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72]='Paul'
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72]='Paul'
2018-07-09
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
95:'Adam',
85:'Lisa',
59:'Bart'
}
2018-07-09
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
2018-07-09
for x in [1,2,3,4,5,6,7,8,9]:
for y in [1,2,3,4,5,6,7,8,9]:
if x < y:
print x * 10 + y
for y in [1,2,3,4,5,6,7,8,9]:
if x < y:
print x * 10 + y
2018-07-09
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
else:
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
else:
sum = sum + x
print sum
2018-07-09
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n > 20:
break
print sum
2018-07-09
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k in d:
sum = sum + d[k]
print k,':',d[k]
print 'average', ':', sum/len(d)
sum = 0.0
for k in d:
sum = sum + d[k]
print k,':',d[k]
print 'average', ':', sum/len(d)
2018-07-08
def toUppers(L):
m = []
for x in L:
if(isinstance(x,str)):
m.append(x.upper())
return m
print toUppers(['Hello', 'world', 101])
我一开始写的,好繁琐。。。
m = []
for x in L:
if(isinstance(x,str)):
m.append(x.upper())
return m
print toUppers(['Hello', 'world', 101])
我一开始写的,好繁琐。。。