作者b98204030 (佳佳)
看板Python
标题[问题] 相同的程式码换电脑後就出现SyntaxError
时间Thu Mar 21 13:31:30 2013
在学校打的程式码是OK的
可是回家後几安装python3.3
一样的程式码,却出现error
以下是程式码
是要让出现找不到那麽多个数字的时候知道是没有那麽多个数字
我想要找第n个数字是什麽,但数列中没有第n个数字
所以最後要显示这个数列没有n个数字
请各位大大帮忙解惑,感谢
car = lambda lst : lst [0]
cdr = lambda lst : lst [1:]
def nth_element (lst, n, ori):
'''
nth_element(lst, n) = the n-th element of lst
'''
if lst == []:
return report_list_does_not_have(ori, n)
elif n == 0:
return car(lst)
else:
return nth_element(cdr(lst), n-1, ori)
def report_does_not_have(lst, n):
print(lst, "does not have &d elements." % (n + 1 + len(lst)))
return None
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.165.97.82
1F:→ ck574b027:你def的函式不是report_list_does_not_have啊 03/21 13:58
2F:推 Yukirin:第一个def後面 函数名跟()中间空格拿掉看看 03/21 19:04
3F:→ kdjf:你的error是什麽? 03/21 20:58
4F:→ grapherd:把report_does_not_hav 放到 nth_element上面看看 03/21 22:03
5F:→ grapherd:......两个函数名称错了而已.. 03/21 22:04
6F:→ b98204030:XDDD我自己也看到了 感谢各位~~ 03/21 23:10
7F:→ b98204030:还有最後面应该是%d 03/21 23:10