错误内容:9.try-except-else-finally下代码
print "Output #142 (Error): " + str(float('nan'))
应改为:print("Output #142 (Error):{}".format(float('nan')))
print "Output #142 (Error):", detail
应改为:print("Output #142 (Error): {}".format(detail))
print "Output #142 (The mean is):", result
应改为:print("Output #142 (The mean is): {}".format(result))
print "Output #142 (Finally): The finally block is executed every time"
应改为:print("Output #142 (Finally): The finally block is executed every time")
应改为:pattern = re.compile(r"(?P<match_word>The)", re.I)
应改为:“print("{:s}".format(pattern.search(word).group('match_word')))”
应改为:print("Output #40:{:s}".format(pattern.sub("a", string)))
应改为:ordered_dict1 = sorted(dict_copy.items(), key=lambda item: item[0])
def getMean(numericValues):
return sum(numericValues)/len(numericValues) if len(numericValues) >0
else float('nan')
应改为:
def getMean(numericValues):
return sum(numericValues)/len(numericValues) if len(numericValues) >0 \
else float('nan')
print("output #135 (mean): {!s}".format(getMean(my_list))
应改为:
print("output #135 (mean): {!s}".format(getMean(my_list)))
print "Output #142 (Error): " + str(float('nan'))
应改为:print("Output #142 (Error):{}".format(float('nan')))
print "Output #142 (Error):", detail
应改为:print("Output #142 (Error): {}".format(detail))
print "Output #142 (The mean is):", result
应改为:print("Output #142 (The mean is): {}".format(result))
print "Output #142 (Finally): The finally block is executed every time"
应改为:print("Output #142 (Finally): The finally block is executed every time")
print "Output #143: "
应改为:print("Output # 143:")
print row.strip( )
应改为:print(row.strip( ))
for row in filereader:
print("{}".format(row.strip()))
应改为:将此两行代码各向右缩进1tab
for row in filereader:
print("{}".format(row.strip()))
应改为:将此两行代码各向右缩进1tab