......
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td>' % (name,score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
......
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td>' % (name,score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
......
2016-09-24
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
2016-09-24
最新回答 / AlvinYuan
y处于内层循环,内层循环完毕后, 外层循环才会开始下一层循环。因此,x每循环一次,y都要循环三次。具体运行情况如下:x第一次循环:x=A y第一次循环:y=1 ,此时打印A1 y第二次循环:y=2 ,此时打印A2 y第三次循环:y=3 ,此时打印A3 内层循环结束,开始外层第二次循环x第二次循环:x=B y第一次循环:y=1 ,此时打印B1 y第二次循环:y=2 ,此时打印B2 y第三次循环:y=3 ,此时打印B3 内层循环结束,开始外层第三...
2016-09-24
已采纳回答 / 超级无敌美少女战士
因为第一个代码‘b,’'c'之间没有逗号,python默认把它们算成一个字符串‘b,c’.同理‘1,' '2,' '3’之间也没有逗号,python把它们识别成‘1,2,3’所以你的一个代码实际上是 for x in ['a', 'b,c']: for y in ['1,2,3'] 最后的输出结果为a1,2,3 和b,c1,2,3.
2016-09-24
最新回答 / AlvinYuan
1. 开头两行是变量初始化,因为变量作用域的关系, 他需要在while循环外进行初始化2. 注意看if的条件, 只有当x大于100之后才会进入这个if语句执行break,在此之前,执行的是其他语句
2016-09-24
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2016-09-24
s = 'python was started in 1989 by "guido".\npython is free and easy to learn.'
print s
print s
2016-09-24
L = ['Adam', 'lisa', 'Bart']
a = L.pop()
b = L.pop(0)
L.insert(0,a)
L.insert(2,b)
print L
a = L.pop()
b = L.pop(0)
L.insert(0,a)
L.insert(2,b)
print L
2016-09-24
print [int(str(x)+str(y)+str(x)) for x in range(1,10) for y in range(0,10)]
2016-09-24