sum = 0
x = 1
n = 1
while True:
x=x*2
sum = sum + x
n=n+1
if n>=20:
sum = sum +1
break
print sum
x = 1
n = 1
while True:
x=x*2
sum = sum + x
n=n+1
if n>=20:
sum = sum +1
break
print sum
2016-01-05
将源代码
age = 8
if age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
改为:
age = 8
if age < 6:
print 'kid'
elif age < 18:
print 'teenager'
else:
print 'adult'
age = 8
if age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
改为:
age = 8
if age < 6:
print 'kid'
elif age < 18:
print 'teenager'
else:
print 'adult'
2016-01-05
#将文件保存为 test.py
def generate_tr(name,score):
if score<60 :
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name,score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name,score)
#用shell执行
python test.py>test.html
firefox test.html
def generate_tr(name,score):
if score<60 :
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name,score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name,score)
#用shell执行
python test.py>test.html
firefox test.html
2016-01-05
这里的实验还是和实际有冲突 Python3.5的print输出是需要()扩起来的,这里用了()后,print把()当作字符输出了
2016-01-05
def move(n,a,b,c):
if n == 1:
print(a,'-->',c)
return
else:
move(n-1,a,c,b)
print(a,'-->',c)
move(n-1,b,a,c)
print(move(4,'A','B','C'))
if n == 1:
print(a,'-->',c)
return
else:
move(n-1,a,c,b)
print(a,'-->',c)
move(n-1,b,a,c)
print(move(4,'A','B','C'))
2016-01-04