>>> sc=65
>>> if sc>=90:
print 'excellent'
elif sc>=80:
print 'good'
elif sc>=60:
print 'passed'
else:
print 'failed'
passed
>>>
>>> if sc>=90:
print 'excellent'
elif sc>=80:
print 'good'
elif sc>=60:
print 'passed'
else:
print 'failed'
passed
>>>
2016-09-26
问题:使用IDEL编译Python代码,自带行缩进功能。因此每次输入else:
都会出现:IndentationError: unindent does not match any outer indentation level问题
解决办法:if前面虽然有>>>3个占位符,但是if实际上还是顶格,首行缩进为0,所以在输入else之前,使用Backspace,使else首行缩进为0.
代码:
>>> score=55
>>> if score<=60:
print 'Failed'
else:
print 'Passed'
Failed
都会出现:IndentationError: unindent does not match any outer indentation level问题
解决办法:if前面虽然有>>>3个占位符,但是if实际上还是顶格,首行缩进为0,所以在输入else之前,使用Backspace,使else首行缩进为0.
代码:
>>> score=55
>>> if score<=60:
print 'Failed'
else:
print 'Passed'
Failed
2016-09-26
print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(0,10) if a==c]
2016-09-26
已采纳回答 / qq_李小勺_0
<...code...>这段生成的是HTML代码,你需要把它另存到一个文本文件中,格式为 .html,用浏览器打开就看到表格了。建议你需要了解一些HTML的知识,简单得很。
2016-09-26
tds = [generate_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)
if score<60:
<td style="color:red">
print '</table>'
print '<table border="1">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
if score<60:
<td style="color:red">
print '</table>'
2016-09-26
第一次删除Paul后,Bart补上来,队伍中没有3号人物了,所以不对呀。应该还是删除2号或者-1,在List较长时,不记得总数直接-1比较方便。。。
2016-09-26
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0],':',x[1]
for x in s:
print x[0],':',x[1]
2016-09-25
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2016-09-25
已采纳回答 / rubyc
你这是递归思想还没有形成,主要问题不在于return,函数体中遇到return函数就结束了,之所以调用很多次是因为递归的原因,return的位置取决于你想让它在函数体中什么情况下结束。
2016-09-25