sum = 0
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n=n+1
if n>20:
break
print sum
2019-12-22
print key,':',d['key'] 这样冒号前后都会有空格 如果不想有空格:print key+':'+str(d['key'])
2019-12-20
print([x*100+y*10+x for x in range(1,10) for y in range(0,10) ])这样写也可以呀,两个循环就好了
2019-12-18
L = range(0,101)
def sum(x):
s2=0
for i in L:
s1=i*i
s2 += s1
return s2
print sum(L)
def sum(x):
s2=0
for i in L:
s1=i*i
s2 += s1
return s2
print sum(L)
2019-12-17
亲测:
print [int(str(a)+str(b)+str(a)) for a in range(1,10) for b in range(0,10)]
print [int(str(a)+str(b)+str(a)) for a in range(1,10) for b in range(0,10)]
2019-12-17
def toUppers(L):
return [x.upper() for x in L if isinstance(x, str) ]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x, str) ]
print toUppers(['Hello', 'world', 101])
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
tds = ['<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score) for name, score in d.iteritems()]
print '<table border="1">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
tds = ['<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score) for name, score in d.iteritems()]
print '<table border="1">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
2019-12-17
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2019-12-17
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n=0
sum = 0.0
for k, v in d.iteritems():
n=n+1
sum = sum + v
print k,':',v
print 'average', ':', sum/n
n=0
sum = 0.0
for k, v in d.iteritems():
n=n+1
sum = sum + v
print k,':',v
print 'average', ':', sum/n
2019-12-17
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n=0
sum = 0.0
for x in d.itervalues():
n=n+1
sum=sum+x
print sum/n
n=0
sum = 0.0
for x in d.itervalues():
n=n+1
sum=sum+x
print sum/n
2019-12-17