for x in range(1, 10):
for y in range(10):
if x < y:
print x * 10 + y
else:
continue
for y in range(10):
if x < y:
print x * 10 + y
else:
continue
2015-07-08
sum = 0
i = 1
x = 1
while True:
sum += x
if i < 20:
x = x * 2
i += 1
else:
break
print sum
i = 1
x = 1
while True:
sum += x
if i < 20:
x = x * 2
i += 1
else:
break
print sum
2015-07-08
sum = 0
x = 1
while x <= 100:
if x % 2 ==1:
sum += x
print sum
x = 1
while x <= 100:
if x % 2 ==1:
sum += x
print sum
2015-07-08
为什么一定要加 r ?其实就这题而言,这个 r 写不写结果都一样吧。因为三引号里面的双引号和单引号本来就不需要转义
2015-07-08
#encoding:utf8
L=['Adam','Lisa','Bart','Paul']
n=0
for i in L:
print "名字为"+i+"的索引为:",L.index(i)
n+=1
L=['Adam','Lisa','Bart','Paul']
n=0
for i in L:
print "名字为"+i+"的索引为:",L.index(i)
n+=1
print "方法一"
for i in range(1,101)[6::7]:
print i
print "方法二"
for i in range(1,101):
if i%7==0:
print i
for i in range(1,101)[6::7]:
print i
print "方法二"
for i in range(1,101):
if i%7==0:
print i
L = range(1, 101)
print L[:10]
print L[2:100:3]
print L[4:50:5]
print L[:10]
print L[2:100:3]
print L[4:50:5]
2015-07-07
def cal(m):
s=0
n=m
while True:
s=s+n*n
n=n+1
if n>100:
break
else:
pass
print s
cal(1)
s=0
n=m
while True:
s=s+n*n
n=n+1
if n>100:
break
else:
pass
print s
cal(1)
2015-07-06