L = [95.5, 85, 59]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
2016-02-18
def greet(a='world.'):
print 'Hello,', a
greet()
greet('Bart')
print 'Hello,', a
greet()
greet('Bart')
2016-02-18
sum = 0
x = 1
while x <= 100:
if x % 2 == 1:
sum = sum + x
x = x + 1
print sum
x = 1
while x <= 100:
if x % 2 == 1:
sum = sum + x
x = x + 1
print sum
2016-02-18
#!/usr/bin/python
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d:
print i,':',d[i]
sum = sum + d[i]
print 'average', ':', sum /len(d)
也行
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d:
print i,':',d[i]
sum = sum + d[i]
print 'average', ':', sum /len(d)
也行
2016-02-18
L = [1]
n=1
while n<100:
n=n+1
L.insert(n,n*n)
print sum(L)
n=1
while n<100:
n=n+1
L.insert(n,n*n)
print sum(L)
2016-02-18
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop()
L.pop()
print L
L.pop()
L.pop()
print L
2016-02-17
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
L.pop(2)
L.pop(2)
print L
2016-02-17