L = []
i = 1
while i < 101:
L.append(i*i)
i = i + 1
print sum(L)
i = 1
while i < 101:
L.append(i*i)
i = i + 1
print sum(L)
2018-04-24
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0] + ':' + str(x[1])
for x in s:
print x[0] + ':' + str(x[1])
2018-04-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name + ':' + str(d[name])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name + ':' + str(d[name])
2018-04-24
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = 2**n
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = 2**n
n = n + 1
if n > 20:
break
print sum
2018-04-23
这两段代码有何不同?
for x in [1,2,3,4,5,6,7,8,9]:
for y in [0,1,2,3,4,5,6,7,8,9]:
if x >= y:
continue
print x*10+y
a = [1,2,3,4,5,6,7,8,9]
b = [0,1,2,3,4,5,6,7,8,9]
for x in a:
for y in b:
if x >= y:
continue
print x*10+y
for x in [1,2,3,4,5,6,7,8,9]:
for y in [0,1,2,3,4,5,6,7,8,9]:
if x >= y:
continue
print x*10+y
a = [1,2,3,4,5,6,7,8,9]
b = [0,1,2,3,4,5,6,7,8,9]
for x in a:
for y in b:
if x >= y:
continue
print x*10+y
2018-04-23
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,len(L)+1),L):
print index, '-', name
for index, name in zip(range(1,len(L)+1),L):
print index, '-', name
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2018-04-23
a = [1,2,3,4,5,6,7,8,9]
b = [0,1,2,3,4,5,6,7,8,9]
for x in a:
for y in b:
if x >= y:
continue
print x*10+y
b = [0,1,2,3,4,5,6,7,8,9]
for x in a:
for y in b:
if x >= y:
continue
print x*10+y
2018-04-23
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
for a in d:
print a,':',d[a]
95:'Adam',
85:'Lisa',
59:'Bart'
}
for a in d:
print a,':',d[a]
2018-04-23
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in ['Adam','Lisa','Bart']:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in ['Adam','Lisa','Bart']:
print key,':',d[key]
2018-04-23