L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[-1]
这样也可以通过。
print L[0]
print L[1]
print L[2]
print L[-1]
这样也可以通过。
2015-03-18
L=[]
sum = 0
for x in range (0,100):
if x%2!=0:
L.append(x)
for x in L:
sum = sum + x
print sum
sum = 0
for x in range (0,100):
if x%2!=0:
L.append(x)
for x in L:
sum = sum + x
print sum
2015-03-18
sum=0
for x in range(0,20):
sum = sum + pow(2,x)
print sum
for x in range(0,20):
sum = sum + pow(2,x)
print sum
2015-03-18
sum = 0
n = 1
while True:
if n > 19:
break
sum = sum +pow(2,n)
n = n + 1
print sum
觉得还是这个简单
n = 1
while True:
if n > 19:
break
sum = sum +pow(2,n)
n = n + 1
print sum
觉得还是这个简单
2015-03-18
def firstCharUpper(s):
return s[0].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
留个脚印
return s[0].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
留个脚印
2015-03-18
L = range(1, 101)
print L[0:10]
print L[2::3]
print L[4:50:5]
留个脚印,第一个是 参数是索引
print L[0:10]
print L[2::3]
print L[4:50:5]
留个脚印,第一个是 参数是索引
2015-03-18
L=[]
for a in range(1,10):
for b in range(10):
L.append(100*a+10*b+a)
print L
for a in range(1,10):
for b in range(10):
L.append(100*a+10*b+a)
print L
2015-03-18
print [x*y for x,y in zip(range(1,101,2),range(2,101,2))]
zip()函数可以把两个list变成一个list,中间用,隔开
zip()函数可以把两个list变成一个list,中间用,隔开
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.items()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
print d.items()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-03-18