L = [95.5, 85, 59]
print 'Bart9[-1],'
print 'Lisa[-2],'
print 'Adam[-3],'
print 'list index out of range'
为什么不可以呢??请问我哪里错了
print 'Bart9[-1],'
print 'Lisa[-2],'
print 'Adam[-3],'
print 'list index out of range'
为什么不可以呢??请问我哪里错了
2015-01-25
这样写也可以:
print [str(x)+str(y)+str(z) for x in range(1, 10) for y in range(10) for z in range(1, 10) if x == z]
print [str(x)+str(y)+str(z) for x in range(1, 10) for y in range(10) for z in range(1, 10) if x == z]
2015-01-25
分享一下我的代码:
print [int(a+b+a) for a in '123456789' for b in '0123456789']
print [int(a+b+a) for a in '123456789' for b in '0123456789']
2015-01-25
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart',
}
print d.get(95)
print d.get(85)
print d.get(59)
95: 'Adam',
85: 'Lisa',
59: 'Bart',
}
print d.get(95)
print d.get(85)
print d.get(59)
2015-01-24
sum = 0
x = 0.0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
x = 0.0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
2015-01-23
def square_of_sum(L):
L= [elem * elem for elem in L]
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
L= [elem * elem for elem in L]
return sum(L)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-01-23